Explore topic-wise MCQs in C++ Programming.

This section includes 6 Mcqs, each offering curated multiple-choice questions to sharpen your C++ Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
virtual void print() const = 0;
};
class DerivedClassOne : public BaseClass
{
public:
void print() const
{
cout << "Derived class One n";
}
};
class DerivedClassTwo : public BaseClass
{
public:
void print() const
{
cout << "Derived class Two n";
}
};
class MultipleClass : public DerivedClassOne, public DerivedClassTwo
{
public:
void print() const
{
DerivedClassTwo :: print();
}
};
int main()
{
int i;
MultipleClass both;
DerivedClassOne one;
DerivedClassTwo two;
BaseClass *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &one;
array[ 2 ] = &two;
array[ i ] -> print();
return 0;
}

A. Derived class Two
B. Derived class One
C. Compilation Error
D. Runtime Error
E. None of these
Answer» D. Runtime Error
2.

What is the output of this program?
#include <iostream>
using namespace std;
struct Student1
{
int num;
};
struct Student2
{
int* val;
};
struct Student3 : public Student1, public Student2
{
};
int main()
{
Student3* ptr = new Student3;
ptr->val = 0;
cout << "Above structures are Inherited...";
return 0;
}

A. Compilation Error
B. Runtime Error
C. Above structures are Inherited...
D. Garbage value
E. None of these
Answer» D. Garbage value
3.

What is the output of this program?
#include 
using namespace std;
class StudentClass
{
public:
int RollNo , mark1 , mark2 ;
void get()
{
RollNo = 25, mark1 = 15, mark2 = 40;
}
};
class sportsClass
{
public:
int sortMarks;
void getsm()
{
sortMarks = 20;
}
};
class statementClass:public StudentClass,public sportsClass
{
int Total,average;
public:
void display()
{
Total = (mark1 + mark2 + sortMarks);
average = Total / 3;
cout << Total << " ";
cout << average;
}
};
int main()
{
statementClass object;
object.get();
object.getsm();
object.display();
}

A. 25 15
B. 40 15
C. 75 25
D. 25 75
E. None of these
Answer» D. 25 75
4.

What is meant by multiple inheritance?

A. Deriving a derived class from base class
B. Deriving a derived class from more than one base class
C. Deriving a base class from derived class
D. All of above
E. None of these
Answer» C. Deriving a base class from derived class
5.

What are the things are inherited from the base class?

A. Friends
B. Constructor and its destructor
C. Operator=() members
D. All of above
E. None of these
Answer» E. None of these
6.

Which design patterns benefit from the multiple inheritances?

A. Code pattern
B. Glue pattern
C. Adapter and observer pattern
D. All of above
E. None of these
Answer» D. All of above