Explore topic-wise MCQs in C++ Programming.

This section includes 41 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.

Which of the following statement is correct about the program given below? #include class BixData { int x, y, z; public: BixData(int xx, int yy, int zz) { x = ++xx; y = ++yy; z = ++zz; } void Show() { cout<< " << x++ << " " << y++ << " " << z++; } }; int main() { BixData objData(1, 2, 3); objData.Show(); return 0; }

A. The program will print the output 1 2 3.
B. The program will print the output 2 3 4 .
C. The program will print the output 4 5 6.
D. The program will report compile time error.
Answer» C. The program will print the output 4 5 6.
2.

Which of the following means ''The use of an object of one class in definition of another class''?

A. Encapsulation
B. inheritance
C. Composition
D. Abstraction
Answer» D. Abstraction
3.

Which of the following statement is correct about the program given below? #include class BixData { int x, y, z; public: BixData(int xx, int yy, int zz) { x = ++xx; y = ++yy; z = ++zz; } void Show() { cout<< "" << x++ << " " << y++ << " " << z++; } }; int main() { BixData objData(1, 2, 3); objData.Show(); return 0; }

A. The program will print the output 1 2 3.
B. The program will print the output 2 3 4 .
C. The program will print the output 4 5 6.
D. The program will report compile time error.
Answer» C. The program will print the output 4 5 6.
4.

What will be the output of the following program? #include #include class IndiaBix { int val; public: void SetValue(char *str1, char *str2) { val = strcspn(str1, str2); } void ShowValue() { cout<< val; } }; int main() { IndiaBix objBix; objBix.SetValue((char*)"India", (char*)"Bix"); objBix.ShowValue(); return 0; }

A. 2
B. 3
C. 5
D. 8
Answer» C. 5
5.

Which of the following statement is correct about the program given below? #include class BixBase { int x, y; public: BixBase(int xx = 10, int yy = 10) { x = xx; y = yy; } void Show() { cout<< x * y << endl; } }; class BixDerived : public BixBase { private: BixBase objBase; public: BixDerived(int xx, int yy) : BixBase(xx, yy), objBase(yy, yy) { objBase.Show(); } }; int main() { BixDerived objDev(10, 20); return 0; }

A. The program will print the output 100.
B. The program will print the output 200.
C. The program will print the output 400.
D. The program will print the output Garbage-value.
Answer» D. The program will print the output Garbage-value.
6.

Which of the following statement is correct about the program given below? #include class IndiaBix { int x; float y; public: void Function() { x = 4; y = 2.50; delete this; } void Display() { cout<< x << " " << y; } }; int main() { IndiaBix *pBix = new IndiaBix(); pBix->Function(); pBix->Function(); pBix->Display(); return 0; }

A. The program will print the output 4 2.5.
B. The program will print the output 4.
C. The program will report runtime error.
D. The program will report compile time error.
Answer» D. The program will report compile time error.
7.

Which of the following statement is correct about the program given below? #include #include class IndiaBix { static int x; public: IndiaBix() { if(x == 1) exit(0); else x++; } void Display() { cout<< x << " "; } }; int IndiaBix::x = 0; int main() { IndiaBix objBix1; objBix1.Display(); IndiaBix objBix2; objBix2.Display(); return 0; }

A. The program will print the output 1 2.
B. The program will print the output 0 1.
C. The program will print the output 1 1.
D. The program will print the output 1.
Answer» E.
8.

What will be the output of the following program? #include class Point { int x, y; public: Point(int xx = 10, int yy = 20) { x = xx; y = yy; } Point operator + (Point objPoint) { Point objTmp; objTmp.x = objPoint.x + this->x; objTmp.y = objPoint.y + this->y; return objTmp; } void Display(void) { cout<< x << " " << y; } }; int main() { Point objP1; Point objP2(1, 2); Point objP3 = objP1 + objP2; objP3.Display(); return 0; }

A. 1 2
B. 10 20
C. 11 22
D. Garbage Garbage
Answer» D. Garbage Garbage
9.

Which of the following statement is correct about the program given below? #include class BixBase { int x, y; public: BixBase(int xx = 10, int yy = 10) { x = xx; y = yy; } void Show() { cout<< x * y << endl; } }; class BixDerived : public BixBase { private: BixBase objBase; public: BixDerived(int xx, int yy) : BixBase(xx, yy) { objBase.Show(); } }; int main() { BixDerived objDev(10, 20); return 0; }

A. The program will print the output 100.
B. The program will print the output 200.
C. The program will print the output Garbage-value.
D. The program will report compile time error.
Answer» B. The program will print the output 200.
10.

What will be the output of the following program? #include #include class IndiaBix { char str[50]; char tmp[50]; public: IndiaBix(char *s) { strcpy(str, s); } int BixFunction() { int i = 0, j = 0; while(*(str + i)) { if(*(str + i++) == ' ') *(tmp + j++) = *(str + i); } *(tmp + j) = 0; return strlen(tmp); } }; int main() { char txt[] = "Welcome to IndiaBix.com!"; IndiaBix objBix(txt); cout<< objBix.BixFunction(); return 0; }

A. 1
B. 2
C. 24
D. 25
Answer» C. 24
11.

What will be the output of the following program? #include class BixBase { public: float x; }; class BixDerived : public BixBase { public: char ch; void Process() { ch = (int)((x=12.0)/3.0); } void Display() { cout<< (int)ch; } }; int main() { class BixDerived *objDev = new BixDerived; objDev->Process(); objDev->Display(); return 0; }

A. The program will print the output 4.
B. The program will print the ASCII value of 4.
C. The program will print the output 0.
D. The program will print the output garbage.
Answer» B. The program will print the ASCII value of 4.
12.

Which of the following statement is correct about the program given below? #include #include class IndiaBix { public: void GetData(char *s, int x, int y ) { int i = 0; for (i = x-1; y>0; i++) { cout<< s[i]; y--; } } }; int main() { IndiaBix objBix; objBix.GetData((char*)"Welcome!", 1, 3); return 0; }

A. The program will print the output me!.
B. The program will print the output Wel.
C. The program will print the output !em.
D. The program will print the output Welcome!.
Answer» C. The program will print the output !em.
13.

Which of the following statement is correct about the program given below? #include class BixBase { int x, y; public: BixBase(int xx = 10, int yy = 10) { x = xx; y = yy; } void Show() { cout<< x * y << endl; } }; class BixDerived { private: BixBase objBase; public: BixDerived(int xx, int yy) : objBase(xx, yy) { objBase.Show(); } }; int main() { BixDerived objDev(10, 20); return 0; }

A. The program will print the output 100.
B. The program will print the output 200.
C. The program will print the output Garbage-value.
D. The program will report compile time error.
Answer» C. The program will print the output Garbage-value.
14.

Which of the following statement is correct about the program given below? #include class IndiaBix { static int x; public: static void SetData(int xx) { x = xx; } static void Display() { cout<< x ; } }; int IndiaBix::x = 0; int main() { IndiaBix::SetData(44); IndiaBix::Display(); return 0; }

A. The program will print the output 0.
B. The program will print the output 44.
C. The program will print the output Garbage.
D. The program will report compile time error.
Answer» C. The program will print the output Garbage.
15.

What does a class hierarchy depict?

A. It shows the relationships between the classes in the form of an organization chart.
B. It describes "has a" relationships.
C. It describes "kind of" relationships.
D. It shows the same relationship as a family tree.
Answer» D. It shows the same relationship as a family tree.
16.

Which of the following means "The use of an object of one class in definition of another class"?

A. Encapsulation
B. Inheritance
C. Composition
D. Abstraction
Answer» D. Abstraction
17.

What will be the output of the following program? #include class A { public: void BixFunction(void) { cout<< "Class A" << endl; } }; class B: public A { public: void BixFunction(void) { cout<< "Class B" << endl; } }; class C : public B { public: void BixFunction(void) { cout<< "Class C" << endl; } }; int main() { A *ptr; B objB; ptr = &objB; ptr = new C(); ptr->BixFunction(); return 0; }

A. Class A.
B. Class B.
C. Class C.
D. The program will report compile time error.
Answer» B. Class B.
18.

Which of the following statement is correct about the program given below? #include class IndiaBix { static int x; public: static void SetData(int xx) { x = xx; } void Display() { cout<< x ; } }; int IndiaBix::x = 0; int main() { IndiaBix::SetData(33); IndiaBix::Display(); return 0; }

A. The program will print the output 0.
B. The program will print the output 33.
C. The program will print the output Garbage.
D. The program will report compile time error.
Answer» E.
19.

Which of the following access specifies is used in a class definition by default?

A. Protected
B. Public
C. Private
D. Friend
Answer» D. Friend
20.

What will be the output of the following program? #include class IndiaBix { static int count; public: static void First(void) { count = 10; } static void Second(int x) { count = count + x; } static void Display(void) { cout<< count << endl; } }; int IndiaBix::count = 0; int main() { IndiaBix :: First(); IndiaBix :: Second(5); IndiaBix :: Display(); return 0; }

A. 0  
B. 5
C. 10
D. 15
Answer» E.
21.

Which of the following statement is correct about the program given below? #include class IndiaBix { static int x; public: static void SetData(int xx) { this->x = xx; } static void Display() { cout<< x ; } }; int IndiaBix::x = 0; int main() { IndiaBix::SetData(22); IndiaBix::Display(); return 0; }

A. The program will print the output 0.
B. The program will print the output 22.
C. The program will print the output Garbage.
D. The program will report compile time error.
Answer» E.
22.

Which of the following type of data member can be shared by all instances of its class?

A. Public
B. Inherited
C. Static
D. Friend
Answer» D. Friend
23.

Which of the following statements about virtual base classes is correct?

A. It is used to provide multiple inheritance.
B. It is used to avoid multiple copies of base class in derived class.
C. It is used to allow multiple copies of base class in a derived class.
D. It allows private members of the base class to be inherited in the derived class.
Answer» C. It is used to allow multiple copies of base class in a derived class.
24.

Which of the following statements is correct about the constructors and destructors?

A. Destructors can take arguments but constructors cannot.
B. Constructors can take arguments but destructors cannot.
C. Destructors can be overloaded but constructors cannot be overloaded.
D. Constructors and destructors can both return a value.
Answer» C. Destructors can be overloaded but constructors cannot be overloaded.
25.

Which of the following statements is correct when a class is inherited privately?

A. Public members of the base class become protected members of derived class.
B. Public members of the base class become private members of derived class.
C. Private members of the base class become private members of derived class.
D. Public members of the base class become public members of derived class.
Answer» C. Private members of the base class become private members of derived class.
26.

Which of the following keywords is used to control access to a class member?

A. Default
B. Break
C. Protected
D. Asm
Answer» D. Asm
27.

What will be the output of the following program? #include class India { public: struct Bix { int x; float y; void Function(void) { y = x = (x = 4*4); y = --y * y; } void Display() { cout<< y << endl; } }B; }I; int main() { I.B.Display(); return 0; }

A. 0
B. 1
C. -1
D. Garbage value
Answer» B. 1
28.

What does the class definitions in following code represent? class Bike { Engine objEng; }; class Engine { float CC; };

A. kind of relationship
B. has a relationship
C. Inheritance
D. Both A and B
Answer» C. Inheritance
29.

What will be the output of the following program? #include class BixTeam { int x, y; public: BixTeam(int xx) { x = ++xx; } void Display() { cout<< --x << " "; } }; int main() { BixTeam objBT(45); objBT.Display(); int *p = (int*)&objBT; *p = 23; objBT.Display(); return 0; }

A. 45 22
B. 46 22
C. 45 23
D. 46 23
Answer» B. 46 22
30.

Which of the following statements is correct about the program given below? class Bix { public: static void MyFunction(); }; int main() { void(*ptr)() = &Bix::MyFunction; return 0; }

A. The program reports an error as pointer to member function cannot be defined outside the definition of class.
B. The program reports an error as pointer to static member function cannot be defined.
C. The program reports an error as pointer to member function cannot be defined without object.
D. The program reports linker error.
Answer» E.
31.

Which of the following is the only technical difference between structures and classes in C++?

A. Member function and data are by default protected in structures but private in classes.
B. Member function and data are by default private in structures but public in classes.
C. Member function and data are by default public in structures but private in classes.
D. Member function and data are by default public in structures but protected in classes.
Answer» D. Member function and data are by default public in structures but protected in classes.
32.

Which of the following statement is correct with respect to the use of friend keyword inside a class?

A. A private data member can be declared as a friend.
B. A class may be declared as a friend.
C. An object may be declared as a friend.
D. We can use friend keyword as a class name.
Answer» C. An object may be declared as a friend.
33.

Which of the following statements are correct for a static member function? It can access only other static members of its class. It can be called using the class name, instead of objects.

A. Only 1 is correct.
B. Only 2 is correct.
C. Both 1 and 2 are correct.
D. Both 1 and 2 are incorrect.
Answer» D. Both 1 and 2 are incorrect.
34.

Which of the following statements is correct when a class is inherited publicly?

A. Public members of the base class become protected members of derived class.
B. Public members of the base class become private members of derived class.
C. Private members of the base class become protected members of derived class.
D. Public members of the base class become public members of derived class.
Answer» E.
35.

Which of the following statement is correct regarding destructor of base class?

A. Destructor of base class should always be static.
B. Destructor of base class should always be virtual.
C. Destructor of base class should not be virtual.
D. Destructor of base class should always be private.
Answer» C. Destructor of base class should not be virtual.
36.

Which of the following can be overloaded?

A. Object
B. Functions
C. Operators
D. Both B and C
Answer» E.
37.

Which of the following two entities (reading from Left to Right) can be connected by the dot operator?

A. A class member and a class object.
B. A class object and a class.
C. A class and a member of that class.
D. A class object and a member of that class.
Answer» E.
38.

How many objects can be created from an abstract class?

A. Zero
B. One
C. Two
D. As many as we want
Answer» B. One
39.

Which of the following can access private data members or member functions of a class?

A. Any function in the program.
B. All global functions in the program.
C. Any member function of that class.
D. Only public member functions of that class.
Answer» D. Only public member functions of that class.
40.

What will be the output of the following program? #include class Bix { public: int x; }; int main() { Bix *p = new Bix(); (*p).x = 10; cout<< (*p).x << " " << p->x << " " ; p->x = 20; cout<< (*p).x << " " << p->x ; return 0; }

A. 10 10 20 20
B. Garbage garbage 20 20
C. 10 10 Garbage garbage
D. Garbage garbage Garbage garbage
Answer» B. Garbage garbage 20 20
41.

What happens when we try to compile the class definition in following code snippet? class Birds {}; class Peacock : protected Birds {};

A. It will not compile because class body of Birds is not defined.
B. It will not compile because class body of Peacock is not defined.
C. It will not compile because a class cannot be protectedly inherited from other class.
D. It will compile succesfully.
Answer» E.