Questions and Answers
- How many sets of requirements are need in designing a container?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
There are three sets of requirements. They are container interface requirements, Allocator interface requirements and iterator requirements.
- What is the output of this program?
#include <iostream>
using namespace std;
struct N
{
virtual void fun()
{
cout << "Class N" << endl;
}
};
struct M : N
{
virtual void fun()
{
cout << "Class M" << endl;
}
};
struct O : N
{
virtual void fun()
{
cout << "Class O" << endl;
}
};
void fun(N* argumnet)
{
M* ptr1 = dynamic_cast<M*>(argumnet);
O* ptr2 = dynamic_cast<O*>(argumnet);
if (ptr1)
ptr1 -> fun();
else if (ptr2)
ptr2 -> fun();
else
argumnet -> fun();
};
int main()
{
N Object1;
O Object2;
N* ptr1 = &Object2;
N* ptr3 = &Object1;
fun(ptr1);
fun(ptr3);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We applied the dynamic casting to structure and produced the output.
- What is meant by type_info?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Used to hold the type information returned by the typeid operator
- At which time does the static_cast can be applied?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Static_cast can be applied to only compile-time construct and not during run time construct.
- 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;
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, We are using the bad typeid() for a. So it is arising an exception.