Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

At which time does the static_cast can be applied?


  1.    Compile-time construct
  2.    Runtime construct
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Compile-time construct

Static_cast can be applied to only compile-time construct and not during run time construct.


Question 2.

What is meant by type_info?


  1.    Used to hold the type information returned by the typeid operator
  2.    Used to hold the type information returned by the dynamic_cast
  3.    Used to hold the type information returned by the static cast
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Used to hold the type information returned by the typeid operator

None.


Question 3.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
struct A
4.
{
5.
virtual void f()
6.
{
7.
cout
  1.    Class C
  2.    Class A
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Both a & b

In this program, We applied the dynamic casting to structure and produced the output.
Output:
$ g++ rtti4.cpp
$ a.out
Class C
Class A


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
class A
5.
{
6.
public:
7.
virtual ~A();
8.
};
9.
int main()
10.
{
11.
A* a = NULL;
12.
try
13.
{
14.
cout
  1.    int
  2.    float
  3.    double
  4.    object is NULL
 Discuss Question
Answer: Option D. -> object is NULL

In this program, We are using the bad typeid() for a. So it is arising an exception.
Output:
$ g++ rtti3.cpp
$ a.out
object is NULL


Question 5.


What is the output of this program?


1.
#include
2.
#include
3.
#include
4.
using namespace std;
5.
class base
6.
{
7.
virtual void f(){}
8.
};
9.
class derived : public base {};
10.
int main ()
11.
{
12.
try
13.
{
14.
base* a = new base;
15.
base* b = new derived;
16.
cout
  1.    base*
  2.    derived*
  3.    4base and 7derived
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> 4base and 7derived

In this program, We apply the typeid to the polymorphic class.
Output:
$ g++ rtti2.cpp
$ a.out
4base 7derived


Question 6.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
int * a;
7.
int b;
8.
a = 0; b = 0;
9.
if (typeid(a) != typeid(b))
10.
{
11.
cout
  1.    Pi
  2.    i
  3.    Both a & b
  4.    f
 Discuss Question
Answer: Option C. -> Both a & b

In this program, We are finding the typeid of the given variables.
Output:
$ g++ rtti1.cpp
$ a.out
Pii


Question 7.

Which operators are part of RTTI?


  1.    dynamic_cast()
  2.    typeid
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Both a & b

The dynamic_cast<> operation and typeid operator in C++ are part of RTTI.


Question 8.


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
  1.    Null pointer on first type-cast
  2.    Null pointer on second type-cast
  3.    Exception
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Null pointer on second type-cast

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


Question 9.

To which type of class, We can apply RTTI?


  1.    Encapsulation
  2.    Polymorphic
  3.    Derived
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Polymorphic

RTTI is available only for classes which are polymorphic, which means they have at least one 

virtual method.


Question 10.

What is the Run-Time Type Information?


  1.    Information about an object's datatype at runtime
  2.    Information about the variables
  3.    Information about the given block
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Information about an object's datatype at runtime

With the help of RTTI, We can get the information about the data type at the runtime.


Latest Videos

Latest Test Papers