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 : none
What is the output of cout << (6 / 2 * 3) << endl;
1) 9
2) 3
3) 6
4) None of the above
Answer : 9
Which of the following is used for dynamic memory allocation in C++?
1) malloc()
2) free()
3) new
4) All of the above
Answer : All of the above
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 : It has the same name as the class.
What will be the output of cout << (10 & 3) << endl;
1) 2
2) 1
3) 3
4) None of the above
Answer : 2
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 : class derived : public base {}
What is the output of cout << (8 / 4 * 2) << endl;
1) 4
2) 2
3) 0
4) None of the above
Answer : 4
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 : int MyClass::*p;
What is the output of cout << (5 * (2 + 3)) << endl;
1) 25
2) 15
3) 20
4) None of the above
Answer : 25