Questions and Answers
- To which type of class, We can apply RTTI?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
RTTI is available only for classes which are polymorphic, which means they have at least one virtual method.
- Which is used to solve the memory management problem in c++?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
smart pointers
- What are the operators available in dynamic memory allocation?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
new and delete operators are mainly used to allocate and deallocate during runtime.
- What is the output of this program?
#include <iostream>
#include <typeinfo>
#include <exception>
using namespace std;
class BaseClass
{
virtual void f(){}
};
class DerivedClass : public BaseClass {};
int main ()
{
try
{
BaseClass* ptr1 = new BaseClass;
BaseClass* ptr2 = new DerivedClass;
cout << typeid(*ptr1).name() << " ";
cout << typeid(*ptr2).name();
}
catch (exception& excep)
{
cout << "Exception: " << excep.what() << endl;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, We apply the typeid to the polymorphic class.
- What is the Run-Time Type Information?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
With the help of RTTI, We can get the information about the data type at the runtime.