Learn C++ MCQs

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

What is the output of the following code: cout << 5 + 10 << endl;

1) 5

2) 15

3) 10

4) None of the above

Answer : Option 2

Which of the following is a valid way to declare a pointer in C++?

1) int* p;

2) int *p;

3) Both 1 and 2

4) None of the above

Answer : Option 3

What is the correct syntax for a constructor in C++?

1) ClassName() {}

2) ClassName() { }

3) ClassName() : {}

4) ClassName {}

Answer : Option 2

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

1) try-catch

2) throw-catch

3) try-throw

4) handle-exception

Answer : Option 1

What is the output of cout << (10 / 3) << endl;

1) 3

2) 4

3) 3.33

4) 0

Answer : Option 1

Which of the following is not a valid access specifier in C++?

1) public

2) private

3) protected

4) friendly

Answer : Option 4

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

1) class MyClass {}

2) class MyClass()

3) MyClass class {}

4) class MyClass;

Answer : Option 1

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

1) 15

2) 17

3) 20

4) None of the above

Answer : Option 2

Which operator is used for dynamic memory allocation in C++?

1) new

2) malloc

3) alloc

4) create

Answer : Option 1

Which of the following is used to include a header file in C++?

1) #include

2) #include

3) include

4) import

Answer : Option 2