Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    double function(int p, int q)
    {
    if (q == 0)
    {
    throw "Division by zero condition!";
    }
    return (p / q);
    }
    int main ()
    {
    int m = 100;
    int n = 20;
    double Res = 0;
    try
    {
    Res = function(m, n);
    cout << Res;
    }
    catch(const char *message)
    {
    cout << message;
    }
    return 0;
    }
    1. 4
    2. 20
    3. 100
    4. Compilation Error
    5. None of these
Correct Option: A

In this program, we resembling the division by using the exception handling.



Your comments will be displayed only after manual approval.