Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <typeinfo>
    #include <iostream>
    using namespace std;
    class N
    {
    public:
    virtual ~N();
    };
    int main()
    {
    N* ptr = NULL;
    try
    {
    cout << typeid(*ptr).name() << endl;
    }
    catch (bad_typeid)
    {
    cout << "Object is NULL" << endl;
    }
    }
    1. NULL
    2. Compilation Error
    3. Runtime Error
    4. Object is NULL
    5. None of these
Correct Option: D

In this program, We are using the bad typeid() for a. So it is arising an exception.



Your comments will be displayed only after manual approval.