Vidyalelo
C++ Programming · Q661

C++ miscellaneous

Programming · C++ Programming · question 661

Q661

What will be the output of the following C++ code? #include #include using namespace std; class base virtual void dummy() ; class derived: public base int a; ; int main () try base * pba = new derived; base * pbb = new base; derived * pd; pd = dynamic_cast (pba); if (pd == 0) cout (pbb); if (pd == 0) cout << "Null pointer on second type-cast" << endl; catch (exception& e) cout << "Exception: " << e.what(); return 0;

A.
Null pointer on first type-cast
B.
Null pointer on second type-cast
Answer
C.
Exception
D.
Null pointer on third type-cast

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board