Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
    char* p;
    unsigned long int num = (size_t(0) / 3);
    cout << num << endl;
    try
    {
    p = new char[size_t(0) / 3];
    delete[ ] p;
    }
    catch(bad_alloc &TheBadAllocation)
    {
    cout << TheBadAllocation.what() << endl;
    };
    return 0;
    }
    1. 5
    2. 0
    3. depends on compiler
    4. bad_alloc
    5. None of these
Correct Option: B

As we are dividing the zero by three, it is returning 0.



Your comments will be displayed only after manual approval.