Learn C++ MCQs

Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.

What will be the output of cout << (4 + 5 * 2) << endl;

1) 14

2) 13

3) 18

4) None of the above

Answer : 14

What is the purpose of the destructor in C++?

1) To allocate resources

2) To deallocate resources

3) To initialize objects

4) None of the above

Answer : To deallocate resources

Which of the following is the correct way to declare a string in C++?

1) std::string s;

2) string s;

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of cout << (10 - 5 * 2) << endl;

1) 0

2) 5

3) 10

4) None of the above

Answer : Option 1

What does the following code output: cout << (true && false) << endl;

1) 1

2) 0

3) true

4) false

Answer : Option 2

Which of the following is a C++ standard library container?

1) list

2) map

3) set

4) All of the above

Answer : All of the above

What is the output of cout << (6 | 3) << endl;

1) 5

2) 3

3) 7

4) None of the above

Answer : 7

What is the correct way to declare a constant pointer in C++?

1) const int* ptr;

2) int* const ptr;

3) Both 1 and 2

4) None of the above

Answer : int* const ptr;

Which of the following is the correct syntax for a C++ class?

1) class MyClass { public: int x; };

2) class MyClass { int x; };

3) class MyClass { public: void func(); };

4) All of the above

Answer : All of the above

What is the output of cout << (5 + 3) * 2 << endl;

1) 16

2) 10

3) 8

4) None of the above

Answer : 16