1.

What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
class BaseClass
{
virtual void dummy() {}
};
class DerivedClass: public BaseClass
{
int num;
};
int main ()
{
try
{
BaseClass * ptr1 = new DerivedClass;
BaseClass * ptr2 = new BaseClass;
DerivedClass * ptr3;
ptr3 = dynamic_cast(ptr1);
if (ptr3 == 0)
cout << "Null pointer on first type-cast" << endl;
ptr3 = dynamic_cast(ptr2);
if (ptr3 == 0)
cout << "Null pointer on second type-cast" << endl;
}
catch (exception& excep)
{
cout << "Exception: " << excep.what();
}
return 0;
}

A. Null pointer on first type-cast
B. Null pointer on second type-cast
C. Exception:
D. All of above
E. None of these
Answer» C. Exception:


Discussion

No Comment Found

Related MCQs