Learn C++ MCQs
Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.
What will be the output of the following code: cout << (5 == 5) << endl;
1) 1
2) 0
3) 5
4) None of the above
Answer : Option 1
What is the purpose of the `virtual` keyword in C++?
1) To define a function
2) To declare a destructor
3) To enable polymorphism
4) To declare a constructor
Answer : Option 3
Which of the following is the correct way to declare a destructor in C++?
1) ~ClassName() {}
2) ClassName() {}
3) ClassName~() {}
4) ~ClassName {}
Answer : Option 1
What is the output of cout << (true + 2) << endl;
1) 3
2) 1
3) 2
4) true
Answer : Option 1
Which of the following is not a valid type of constructor?
1) Default constructor
2) Parameterized constructor
3) Copy constructor
4) Static constructor
Answer : Option 4
What is the output of cout << (3.0 / 2) << endl;
1) 1
2) 1.5
3) 2
4) 1.0
Answer : Option 2
What is the base class for all classes in C++?
1) object
2) class
3) std
4) None of the above
Answer : Option 4
Which of the following is a feature of C++?
1) Encapsulation
2) Polymorphism
3) Inheritance
4) All of the above
Answer : Option 4
What will be the output of cout << (3 < 5) << endl;
1) 1
2) 0
3) True
4) False
Answer : Option 1
What is the purpose of the `static` keyword when used in a class?
1) To define a class
2) To define a method
3) To declare a member variable
4) To allocate memory
Answer : Option 3