Learn C++ MCQs

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

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

1) public

2) private

3) protected

4) none

Answer : Option 4

What is the output of cout << (6 / 2 * 3) << endl;

1) 9

2) 3

3) 6

4) None of the above

Answer : Option 1

Which of the following is used for dynamic memory allocation in C++?

1) malloc()

2) free()

3) new

4) All of the above

Answer : Option 4

What is the output of cout << (5 == 5 && 4 < 3) << endl;

1) 1

2) 0

3) true

4) false

Answer : Option 2

Which of the following is a characteristic of a constructor in C++?

1) It has the same name as the class.

2) It returns a value.

3) It cannot be overloaded.

4) None of the above

Answer : Option 1

What will be the output of cout << (10 & 3) << endl;

1) 2

2) 1

3) 3

4) None of the above

Answer : Option 1

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

1) class derived : public base {}

2) class derived extends base {}

3) class derived inherits base {}

4) None of the above

Answer : Option 1

What is the output of cout << (8 / 4 * 2) << endl;

1) 4

2) 2

3) 0

4) None of the above

Answer : Option 1

Which of the following is a correct way to define a pointer to a member variable in C++?

1) int MyClass::*p;

2) int *MyClass::p;

3) MyClass::p;

4) None of the above

Answer : Option 1

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

1) 25

2) 15

3) 20

4) None of the above

Answer : Option 1