Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
    double num1 = 9, num2 = 3, Result;
    char Operator = '/';
    try
    {
    if (num2 == 0)
    throw "Division by zero not allowed";
    Result = num1 / num2;
    cout << num1 << " / " << num2 << " = " << Result;
    }
    catch(const char* S)
    {
    cout << "\n Bad Operator: " << S;
    }
    return 0;
    }
    1. 9
    2. 3
    3. 9 / 3 = 3
    4. Bad Operator
    5. None of these
Correct Option: C

In this program, We are dividing the two variables and printing the result. If any one of the operator is zero means, it will arise a exception.



Your comments will be displayed only after manual approval.