Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    #include <math.h>
    using namespace std;
    double Function(double n)
    {
    if (n < 0.0)
    throw "Cannot take sqrt of negative number";
    return sqrt(n);
    }
    int main()
    {
    double n = 16;
    cout << Function(n) << endl;
    }
    1. 0.0
    2. 16
    3. 4
    4. Compilation Error
    5. None of these
Correct Option: C

We are finding the square root of the number, if it is a positive number, it can manipulate, Otherwise it will arise a exception.



Your comments will be displayed only after manual approval.