Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
    int n1 = 20, n2 = 30, n3 = 60;
    float Res;
    try
    {
    if ((n1 - n2) != 0)
    {
    Res = n3 / (n1 - n2);
    cout << Res;
    }
    else
    {
    throw(n1 - n2);
    }
    }
    catch (int k)
    {
    cout<<"Answer is infinite..."<< k;
    }
    }
    1. 20
    2. 30
    3. 60
    4. -6
    5. None of these
Correct Option: D

We are manipulating the values, if there is any infinite value means, it will raise an exception.



Your comments will be displayed only after manual approval.