Learn C++ MCQs
Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.
Which operator is used to dereference a pointer in C++?
1) *
2) &
3) ->
4) ::
Answer : *
What is the output of cout << (1 && 0) << endl;
1) 1
2) 0
3) true
4) false
Answer : Option 2
What is the correct way to include a header file in C++?
1) #include <header.h>
2) #include "header.h"
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What is the purpose of the `static` keyword in C++?
1) To define a static member
2) To define a constant
3) To restrict access
4) All of the above
Answer : All of the above
What will be the output of cout << (15 % 4) << endl;
1) 3
2) 4
3) 1
4) None of the above
Answer : 3
Which of the following is the correct syntax for creating a new thread in C++?
1) std::thread t(func);
2) std::thread t(func());
3) thread t(func);
4) None of the above
Answer : std::thread t(func);
What is the output of cout << (true + false) << endl;
1) 1
2) 0
3) true
4) false
Answer : 1
Which of the following is the correct syntax for using a switch statement in C++?
1) switch (x) { case 1: break; }
2) switch x { case 1: break; }
3) switch (x): { case 1: break; }
4) None of the above
Answer : switch (x) { case 1: break; }
What is the output of cout << (9 ^ 5) << endl;
1) 12
2) 6
3) 4
4) None of the above
Answer : 12
Which of the following is a feature of C++?
1) Encapsulation
2) Inheritance
3) Polymorphism
4) All of the above
Answer : All of the above