Learn C++ MCQs
Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is used for input in C++?
1) cin
2) scanf
3) getline
4) All of the above
Answer : cin
What is the output of cout << (5 && 0) << endl;
1) 1
2) 0
3) 5
4) None of the above
Answer : Option 2
Which of the following is the correct way to declare a class member function?
1) void MyClass::func() {}
2) MyClass::func() {}
3) void func() {}
4) func() MyClass {}
Answer : void MyClass::func() {}
What is the output of cout << (8 >> 1) << endl;
1) 4
2) 8
3) 1
4) None of the above
Answer : 4
Which of the following is the correct way to allocate memory for an object in C++?
1) MyClass *obj = new MyClass();
2) MyClass obj = new MyClass();
3) MyClass *obj; obj = new MyClass;
4) None of the above
Answer : MyClass *obj = new MyClass();
What is the output of cout << (10 / 4) << endl;
1) 2
2) 2.5
3) 3
4) None of the above
Answer : 2
Which of the following is the correct way to define a template function in C++?
1) template<typename T> void func(T t) {}
2) void func<T>(T t) {}
3) template void func(T t) {}
4) None of the above
Answer : template<typename T> void func(T t) {}
What is the output of cout << (3 + 4 * 2) << endl;
1) 11
2) 10
3) 14
4) None of the above
Answer : 11
Which of the following keywords is used to inherit a class in C++?
1) extends
2) implements
3) inherits
4) public
Answer : public
What will be the output of the following code: cout << (2 + 3 * 4) << endl;
1) 14
2) 20
3) 16
4) None of the above
Answer : 14