Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class base { virtual void dummy() {} };
5.
class derived: public base { int a; };
6.
int main ()
7.
{
8.
try
9.
{
10.
base * pba = new derived;
11.
base * pbb = new base;
12.
derived * pd;
13.
pd = dynamic_cast(pba);
14.
if (pd == 0)
15.
cout
Options:
A .  Null pointer on first type-cast
B .  Null pointer on second type-cast
C .  Exception
D .  None of the mentioned
Answer: Option B

In this program, We apply the dynamic cast to pd. Based on the value in the pd, it produces

 the output.
Output:
$ g++ rtti.cpp
$ a.out
Null pointer on second type-cast



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers