Learn C++ MCQs
Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is not a part of object-oriented programming?
1) Encapsulation
2) Inheritance
3) Polymorphism
4) Compilation
Answer : Compilation
What will be the output of cout << (10 > 5 ? 1 : 0) << endl;
1) 1
2) 0
3) 10
4) 5
Answer : 1
What is the output of cout << (sizeof(int) == 4) << endl;
1) 1
2) 0
3) 4
4) None of the above
Answer : 1
Which of the following is the correct way to define a function in C++?
1) void func() {}
2) void func; {}
3) void func() ;
4) func void() {}
Answer : void func() {}
What is the output of cout << (10 % 3) << endl;
1) 1
2) 2
3) 3
4) None of the above
Answer : 1
Which of the following statements is true about inheritance?
1) Derived classes inherit base class members
2) Base class can inherit from derived classes
3) Multiple inheritance is not allowed
4) None of the above
Answer : Derived classes inherit base class members
What is the output of cout << (5 << 1) << endl;
1) 10
2) 5
3) 1
4) None of the above
Answer : 10
Which of the following is the correct way to define a friend function?
1) friend void func();
2) void func() friend;
3) friend void func() {}
4) None of the above
Answer : friend void func();
What is the purpose of the `const` keyword in C++?
1) To define a constant
2) To declare an immutable variable
3) To define a read-only member function
4) All of the above
Answer : All of the above
What is the output of cout << (7 / 2) << endl;
1) 3
2) 3.5
3) 4
4) None of the above
Answer : 3