Explore topic-wise MCQs in C++ Programming.

This section includes 51 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 InterfaceClass
{
public:
virtual void Display() = 0;
};
class ClassA : public InterfaceClass
{
public:
void Display()
{
int num = 10;
cout << num;
}
};
class ClassB : public InterfaceClass
{
public:
void Display()
{
cout < }
};
int main()
{
ClassA object1;
object1.Display();
ClassB object2;
object2.Display();
return 0;
}

A. 10
B. 14
C. 14 10
D. 10 14
E. None of these
Answer» E. None of these
2.

What is the output of this program?
#include <iostream>
using namespace std;
class FirstClass
{
protected:
int width, height;
public:
void set_values (int x, int y)
{
width = x; height = y;
}
virtual int area (void) = 0;
};
class SecondClass: public FirstClass
{
public:
int area (void)
{
return (width * height);
}
};
class ThirdClass: public FirstClass
{
public:
int area (void)
{
return (width * height / 2);
}
};
int main ()
{
SecondClass Rectangle;
ThirdClass trgl;
FirstClass * ppoly1 = &Rectangle;
FirstClass * ppoly2 = &trgl;
ppoly1->set_values (3, 6);
ppoly2->set_values (3, 6);
cout << ppoly1 -> area() < cout << ppoly2 -> area();
return 0;
}

A. 3 6
B. 6 3
C. 9 18
D. 18 9
E. None of these
Answer» E. None of these
3.

What is the output of this program?
#include <iostream>
using namespace std;
class Base
{
int K;
public:
void setInt(int num);
int getInt();
};
class Derived : public Base
{
int L;
public:
void setL(int num);
int multiply();
};
void Base::setInt(int num)
{
K = num;
}
int Base::getInt()
{
return K;
}
void Derived::setL(int num)
{
L = num;
}
int Derived::multiply()
{
return L * getInt();
}
int main()
{
Derived object;
object.setInt(12);
object.setL(3);
cout << object.multiply();
return 0;
}

A. 36
B. 12
C. 3
D. All of above
E. None of these
Answer» B. 12
4.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
virtual void Function()
{
cout << "4";
}
};
class DerivedClassA : public BaseClass
{
public:
void Function()
{
cout << " 5";
}
};
class DerivedClassB : public DerivedClassA
{
public:
void Function()
{
cout << " 6";
}
};
int main()
{
BaseClass *ptr;
BaseClass BaseObject;
DerivedClassA derivedObjectA;
DerivedClassB derivedObjectB;
ptr = &BaseObject;
ptr -> Function();
ptr = &derivedObjectA;
ptr -> Function();
ptr = &derivedObjectB;
ptr -> Function();
return 0;
}

A. 4 5 6
B. 6 5 4
C. 5 6 4
D. 6 4 5
E. None of these
Answer» B. 6 5 4
5.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
int A;
public:
void setA(int num1)
{
A = num1;
}
void showA()
{
cout << A < }
};
class DerivedClass : private BaseClass
{
int B;
public:
void setAB(int num1, int num2)
{
setA(num1);
B = num2;
}
void showAB()
{
showA();
cout << B << ' n';
}
};
int main()
{
DerivedClass object;
object.setAB(15, 25);
object.showAB();
return 0;
}

A. 15
B. 25
C. 25 15
D. 15 25
E. None of these
Answer» E. None of these
6.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
BaseClass(){}
~BaseClass(){}
protected:
private:
};
class DerivedClass:public BaseClass
{
public:
DerivedClass(){}
DerivedClass(){}
private:
protected:
};
int main()
{
cout << "The program exceuted" << endl;
}

A. Compilation Error
B. The program exceuted
C. Runtime Error
D. Garbage value
E. None of these
Answer» C. Runtime Error
7.

What is the output of this program?
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
stringstream strstream(ios :: in | ios :: out);
std :: string data("The double value is : 12.25 .");
strstream.str(data);
strstream.seekg(-5, ios :: end);
double value;
strstream >> value;
value = value*value;
strstream.seekp(-5,ios::end);
strstream << value;
std :: string new_value = strstream.str();
cout << new_value;
return 0;
}

A. 12.25
B. Compilation Error
C. 120.0625
D. Runtime Error
E. None of these
Answer» D. Runtime Error
8.

What is the output of this program?
#include <iostream>
using namespace std;
class Polygon
{
protected:
int W, H;
public:
void set_values(int width, int height)
{
W = width; H = height;
}
};
class Coutput
{
public:
void output(int i);
};
void Coutput::output(int i)
{
cout << i < }
class Rectangle:public Polygon, public Coutput
{
public:
int area()
{
return(W * H);
}
};
class Triangle:public Polygon, public Coutput
{
public:
int area()
{
return(W * H / 2);
}
};
int main()
{
Rectangle Rect;
Triangle trgl;
Rect.set_values(5, 2);
trgl.set_values(5, 2);
Rect.output(Rect.area());
trgl.output(trgl.area());
return 0;
}

A. 5 2
B. 2 5
C. 10 5
D. 5 10
E. None of these
Answer» D. 5 10
9.

What is the output of this program?
#include <iostream>
using namespace std;
class student
{
protected:
int Rollno;
public:
void get_Rollno(int num)
{
Rollno = num;
}
void put_Rollno(void)
{
}
};
class test:public student
{
protected:
float Subject1,Subject2;
public:
void get_mark(float num1, float num2)
{
Subject1 = num1;
Subject2 = num2;
}
void put_marks()
{
}
};
class sports
{
protected:
float score;
public:
void getscore(float s)
{
score = s;
}
void putscore(void)
{
}
};
class result: public test, public sports
{
float total;
public:
void display(void);
};
void result::display(void)
{
total = Subject1 + Subject2 + score;
put_Rollno();
put_marks();
putscore();
cout << "Total Score = " << total << " n";
}
int main()
{
result student;
student.get_Rollno(101);
student.get_mark(50.25, 42.52);
student.getscore(7.0);
student.display();
return 0;
}

A. 50.25
B. 42.52
C. 99.77
D. Compilation Error
E. None of these
Answer» D. Compilation Error
10.

What is the output of this program?
#include <iostream>
using namespace std;
class BaseClass
{
public:
virtual void print() const = 0;
};
class DerivedClassA : virtual public BaseClass
{
public:
void print() const
{
cout << " 5 ";
}
};
class DerivedClassB : virtual public BaseClass
{
public:
void print() const
{
cout << "3";
}
};
class Multiple : public DerivedClassA, DerivedClassB
{
public:
void print() const
{
DerivedClassB::print();
}
};
int main()
{
Multiple both;
DerivedClassA objectA;
DerivedClassB objectB;
BaseClass *array[ 3 ];
array[ 0 ] = &both;
array[ 1 ] = &objectA;
array[ 2 ] = &objectB;
for ( int K = 0; K < 3; K++ )
array[ K ] -> print();
return 0;
}

A. 5 3
B. 3 5 3
C. 3 3 5
D. 5 3 3
E. None of these
Answer» C. 3 3 5
11.

What is the output of this program?
#include <iostream>
using namespace std;
class ClassA
{
public:
virtual void example() = 0;
};
class ClassB:public ClassA
{
public:
void example()
{
cout << "Interview Mania";
}
};
class ClassC:public ClassA
{
public:
void example()
{
cout << " is awesome.";
}
};
int main()
{
ClassA* array[2];
ClassB B;
ClassC C;
array[0]=&B;
array[1]=&C;
array[0]->example();
array[1]->example();
}

A. Interview Mania
B. Interview Mania is awesome.
C. is awesome.
D. Compilation Error
E. None of these
Answer» C. is awesome.
12.

What is the output of this program?
#include <iostream>
using namespace std;
class FirstClass
{
int m;
public:
FirstClass() : m(12)
{
}
FirstClass(int mm): m(mm)
{
}
int getm()
{
return m;
}
};
class SecondClass : public FirstClass
{
int n;
public:
SecondClass(int nn) : n(nn) {}
int getn() { return n; }
};
int main()
{
SecondClass object(105);
cout << object.getm() << " " << object.getn() << endl;
}

A. 12
B. 105
C. 105 12
D. 12 105
E. None of these
Answer» E. None of these
13.

What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "Interview Mania";
str.insert(str.size() / 3, " * ");
cout << str << endl;
return 0;
}

A. Interview
B. Mania
C. Inter * view Mania
D. Interview Mania
E. None of these
Answer» D. Interview Mania
14.

What is the output of this program?
#include <iostream>
using namespace std;
class ExceptionClass
{
public:
ExceptionClass(int value) : mValue(value)
{
}
int mValue;
};
class DerivedExceptionClass : public ExceptionClass
{
public:
DerivedExceptionClass(int value, int anotherValue) : ExceptionClass(value),mAnotherValue(anotherValue)
{
}
int mValue;
int mAnotherValue;
};
void doSomething()
{
throw DerivedExceptionClass(10,20);
}
int main()
{
try
{
doSomething();
}
catch (DerivedExceptionClass &exception)
{
cout << "Caught Derived Class Exception";
}
catch (ExceptionClass &exception)
{
cout << "Caught Base Class Exception";
}
return 0;
}

A. Caught Base Class Exception
B. Compilation Error
C. Caught Derived Class Exception
D. Runtime Error
E. None of these
Answer» D. Runtime Error
15.

What is the output of this program?
#include 
using namespace std;
class Example
{
private:
int num;
public:
void input()
{
cout << num;
}
void Result()
{
cout << "Entered Variable is: ";
cout << num << " n";
}
};
int main()
{
Example obj;
obj.input();
obj.Result();
obj.num();
return 0;
}

A. Runtime Error
B. Garbage value
C. Compilation Error
D. Entered Variable is: 15
E. None of these
Answer» D. Entered Variable is: 15
16.

What is the output of the following program?
#include 
using namespace std;
class BoxVolume
{
public :
double L;
double B;
double H;
};
int main( )
{
BoxVolume Box;
double vol;
Box.H = 3;
Box.L = 4;
Box.B = 2.15;
vol = Box.H * Box.L * Box.B;
cout << "Volume of Box : " << vol < return 0;
}

A. 3
B. 4
C. 2.15
D. 25.8
E. None of these
Answer» E. None of these
17.

What is the output of this program?
#include <iostream>
using namespace std;
class Example
{
public:
Example()
{
cout << "N::N()" << endl;
}
Example( Example const & )
{
cout << "N::N( N const & )" << endl;
}
Example& operator=( Example const & )
{
cout << "N::operator=(N const &)" << endl;
}
};
Example function()
{
Example temp;
return temp;
}
int main()
{
Example p = function();
return 0;
}

A. N::N(N const & )
B. N
C. N::operator=(N const &)
D. N::N()
E. None of these
Answer» E. None of these
18.

What is the output of this program?
#include <iostream>
using namespace std;
class Base
{
protected:
int K;
public:
Base(int num1)
{
K = num1;
}
~Base()
{
}
};
class Derived: public Base
{
int L;
public:
Derived(int num1, int num2): Base(num2)
{
L = num1;
}
~Derived()
{
}
void show()
{
cout << K << " " << L << endl;
}
};
int main()
{
Derived object(5, 6);
object.show();
return 0;
}

A. 5
B. 6
C. 5 6
D. 6 5
E. None of these
Answer» E. None of these
19.

What is the output of this program?
#include <iostream>
using namespace std;
class First
{
public:
First(int num1 )
{
cout << num1 < }
};
class Second: public First
{
public:
Second(int num1, double num2)
: First(num1)
{
cout << num2 < }
};
class Third: public Second
{
public:
Third(int num1, double num2, char ch)
: Second(num1, num2)
{
cout < }
};
int main()
{
Third object(6, 5.35, 'I');
return 0;
}

A. 6 I 5.35
B. 6 3.5
C. I 5.3 6
D. I 6
E. 6 5.35 I
Answer» F.
20.

What is the output of this program?
#include 
using namespace std;
class num
{
int N;
public:
int getN();
void putN(int M);
};
int num::getN()
{
return N;
}
void num::putN(int M)
{
N = M;
}
int main()
{
num obj;
obj.putN(15);
cout << obj.getN( );
return 0;
}

A. Compilation Error
B. Runtime Error
C. Garbage Value
D. 15
E. None of these
Answer» E. None of these
21.

What is the output of this program?
#include 
using namespace std;
class DummyClass
{
public:
int IsItMe (DummyClass& parameter);
};
int DummyClass::IsItMe (DummyClass& parameter)
{
if (&parameter == this)
return true;
else
return false;
}
int main ()
{
DummyClass p;
DummyClass *q = &p;
if (q->IsItMe(p))
{
cout << "Program executed...";
}
else
{
cout< }
return 0;
}

A. Program not execute...
B. Program executed...
C. Compilation Error
D. Runtime Error
E. Garbage Value
Answer» C. Compilation Error
22.

What is the output of this program?
#include <iostream>
using namespace std;
class Rectangle
{
int p, q;
public:
void value (int, int);
int area ()
{
return (p * q);
}
};
void Rectangle::value (int n, int m)
{
p = n;
q = m;
}
int main ()
{
Rectangle Rectangle;
Rectangle.value (6, 5);
cout << "Area of Rectangle : " << Rectangle.area();
return 0;
}

A. Area of Rectangle : 30
B. Area of Rectangle : 3
C. Area of Rectangle : 4
D. Compilation Error
E. None of these
Answer» B. Area of Rectangle : 3
23.

What does the cerr represent?

A. Output stream
B. Input stream
C. Standard logging stream
D. Standard error stream
E. None of these
Answer» E. None of these
24.

How many types of guarantees are there in exception class can have?

A. 4
B. 3
C. 2
D. 1
E. None of these
Answer» C. 2
25.

Which operator is used to create the user-defined streams in c++?

A. <<
B. >>
C. Both >> and <<
D. &
E. None of these
Answer» D. &
26.

How to store the large objects in c++ if it extends its allocated memory?

A. queue
B. memory heap
C. stack
D. All of above
E. None of these
Answer» C. stack
27.

Which special character is used to mark the end of class?

A. $
B. #
C. :
D. ;
E. None of these
Answer» E. None of these
28.

When struct is used instead of the keyword class means, what will happen in the program?

A. access is protected by default
B. access is public by default
C. access is private by default
D. All of above
E. None of these
Answer» C. access is private by default
29.

Which is used to create a pure virtual function ?

A. !
B. &
C. $
D. =0
E. None of these
Answer» E. None of these
30.

Which class is used to design the base class?

A. base class
B. derived class
C. abstract class
D. All of above
E. None of these
Answer» D. All of above
31.

Where does the abstract class is used?

A. funciton
B. derived class
C. base class only
D. both derived & base class
E. None of these
Answer» D. both derived & base class
32.

How many types of class are there in c++?

A. 4
B. 3
C. 2
D. 1
E. None of these
Answer» C. 2
33.

How many ways of reusing are there in the class hierarchy?

A. 4
B. 3
C. 2
D. 1
E. None of these
Answer» D. 1
34.

Which interface determines how your class will be used by another program?

A. private
B. protected
C. public
D. All of above
E. None of these
Answer» D. All of above
35.

Pick out the correct statement about the override.

A. Overriding refers to a derived class
B. Overriding refers to a derived class function that has the same name and signature as a base class virtual function
C. Overriding has different names
D. All of above
E. None of these
Answer» C. Overriding has different names
36.

What is the syntax of inheritance of class?

A. class name: access specifier
B. class name: access specifier class name
C. class name
D. All of above
E. None of these
Answer» C. class name
37.

What does inheritance allow you to do?

A. access methods
B. create a class
C. create a hierarchy of classes
D. All of above
E. None of these
Answer» D. All of above
38.

Pick out the correct statement about multiple inheritances.

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

Which constructor will initialize the base class data member?

A. class
B. derived class
C. base class
D. All of above
E. None of these
Answer» D. All of above
40.

What does derived class does not inherit from the base class?

A. friends
B. operator = () members
C. constructor and destructor
D. All of above
E. None of these
Answer» E. None of these
41.

What should be the name of the constructor?

A. same as the member
B. same as the class
C. same as the object
D. All of above
E. None of these
Answer» C. same as the object
42.

What is the use of clog?

A. Input stream
B. Standard logging stream
C. Error stream
D. All of above
E. None of these
Answer» C. Error stream
43.

Which classes are called as mixin?

A. Standard logging stream
B. Represent a secondary design
C. Classes express functionality which represent responsibilities
D. All of above
E. None of these
Answer» D. All of above
44.

Which operator is used to declare the destructor?

A. $
B.
C. @~
D. #
E. None of these
Answer» D. #
45.

Where is the derived class is derived from?

A. base
B. derived
C. Top
D. both derived & base
E. None of these
Answer» B. derived
46.

Where does the object is created?

A. attributes
B. destructor
C. constructor
D. class
E. None of these
Answer» E. None of these
47.

The fields in the class in c++ program are by default

A. private
B. public
C. protected
D. All of above
E. None of these
Answer» B. public
48.

Which of the following is a valid class declaration?

A. object A { int x; };
B. public class A { }
C. class A { int x; };
D. class B { }
E. None of these
Answer» D. class B { }
49.

Which other keywords are also used to declare the class other than class?

A. union
B. struct
C. both union & struct
D. object
E. None of these
Answer» D. object
50.

Which is used to define the member of a class externally?

A. #
B. :
C. ::
D. All of above
E. None of these
Answer» D. All of above