Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    double Option1 = 12, Option2 = 6, Result;
    char Option;
    try
    {
    if (Option != '+' && Option != '-' && Option != '*' && Option != '/')
    throw Option;
    switch(Option)
    {
    case '+':
    Result = Option1 + Option2;
    break;
    case '-':
    Result = Option1 - Option2;
    break;
    case '*':
    Result = Option1 * Option2;
    break;
    case '/':
    Result = Option1 / Option2;
    break;
    }
    cout << "\n" << Option1 << " " << Option << " "<< Option2 << " = " << Result;
    }
    catch (const char ch)
    {
    cout << ch << "Is not a valid Option...";
    }
    return 0;
    }
    1. Compilation Error
    2. Runtime Error
    3. Garbage Value
    4. Is not a valid Option...
    5. None of these
Correct Option: D

It will arise a exception because we missed a operator.



Your comments will be displayed only after manual approval.