Learn C++ MCQs

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

Which of the following is not a valid use of the `new` operator?

1) int* p = new int;

2) int* p = new int[10];

3) int* p = new int();

4) int p = new int;

Answer : int p = new int;

What 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 will be the output of cout << (10 >> 1) << endl;

1) 5

2) 10

3) 2

4) None of the above

Answer : 5

Which of the following is used to handle exceptions in C++?

1) try

2) catch

3) throw

4) All of the above

Answer : All of the above

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

1) 10

2) 8

3) 6

4) None of the above

Answer : 10

Which of the following is the correct way to declare a static member in a class?

1) static int x;

2) int static x;

3) static x;

4) None of the above

Answer : static int x;

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

1) 10

2) 14

3) 7

4) None of the above

Answer : 10

Which of the following is used to define a virtual function in C++?

1) virtual

2) override

3) abstract

4) None of the above

Answer : virtual

What is the output of cout << (true || false) << endl;

1) 1

2) 0

3) true

4) false

Answer : 1

What is the correct way to declare an array of strings in C++?

1) std::string arr[10];

2) string arr[10];

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2