Learn C++ MCQs

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

Which of the following is used to create a constant in C++?

1) const

2) static

3) readonly

4) immutable

Answer : const

What is the output of cout << (1 && 1) << endl;

1) 1

2) 0

3) true

4) false

Answer : 1

Which of the following is the correct way to declare a template class?

1) template<class T> class MyClass {}

2) class MyClass<T> {}

3) template<class T> MyClass {}

4) None of the above

Answer : template<class T> class MyClass {}

What will be the output of cout << (3.0 / 2) << endl;

1) 1

2) 1.5

3) 2

4) None of the above

Answer : 1.5

Which of the following is used for exception handling in C++?

1) try-catch

2) try-finally

3) catch-finally

4) All of the above

Answer : try-catch

What is the output of cout << (1 | 2) << endl;

1) 3

2) 1

3) 2

4) None of the above

Answer : 3

Which of the following is the correct way to define a multi-dimensional array in C++?

1) int arr[3][4];

2) int arr[4][3];

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of cout << (10 >> 1) << endl;

1) 5

2) 10

3) 1

4) None of the above

Answer : 5

What is the purpose of the `protected` access specifier?

1) To allow access only to derived classes

2) To allow access to all classes

3) To allow access only to base classes

4) None of the above

Answer : To allow access only to derived classes

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

1) 10

2) 15

3) 20

4) None of the above

Answer : 10