Learn C++ MCQs
Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is the correct way to declare an inline function?
1) inline int func() {}
2) int inline func() {}
3) inline func() int {}
4) None of the above
Answer : inline int func() {}
What is the output of cout << (3 & 1) << endl;
1) 1
2) 0
3) 3
4) None of the above
Answer : 1
Which of the following is not a feature of OOP?
1) Encapsulation
2) Abstraction
3) Compilation
4) Inheritance
Answer : Compilation
What will be the output of cout << (true || false) << endl;
1) 1
2) 0
3) true
4) false
Answer : 1
What is the purpose of the `friend` keyword in C++?
1) To declare a function as a friend
2) To allow access to private members
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What is the output of cout << (2 * 3 + 5) << endl;
1) 11
2) 10
3) 12
4) None of the above
Answer : 11
Which of the following is used to exit from a loop in C++?
1) break
2) exit
3) continue
4) return
Answer : break
What is the correct way to initialize a vector in C++?
1) vector<int> v;
2) vector v;
3) vector<int> v = {};
4) None of the above
Answer : vector<int> v;
What will be the output of cout << (3 * 5 < 20) << endl;
1) 1
2) 0
3) True
4) False
Answer : 1
Which of the following is the correct way to define a destructor?
1) ~MyClass() {}
2) MyClass::~MyClass() {}
3) MyClass() ~{}
4) None of the above
Answer : ~MyClass() {}