Learn C++ MCQs
Prepare C++ MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of the following code: cout << 5 + 10 << endl;
1) 5
2) 15
3) 10
4) None of the above
Answer : 15
Which of the following is a valid way to declare a pointer in C++?
1) int* p;
2) int *p;
3) Both 1 and 2
4) None of the above
Answer : Both 1 and 2
What is the correct syntax for a constructor in C++?
1) ClassName() {}
2) ClassName() { }
3) ClassName() : {}
4) ClassName {}
Answer : ClassName() { }
Which of the following is used to handle exceptions in C++?
1) try-catch
2) throw-catch
3) try-throw
4) handle-exception
Answer : try-catch
What is the output of cout << (10 / 3) << endl;
1) 3
2) 4
3) 3.33
4) 0
Answer : 3
Which of the following is not a valid access specifier in C++?
1) public
2) private
3) protected
4) friendly
Answer : friendly
What is the correct way to declare a class in C++?
1) class MyClass {}
2) class MyClass()
3) MyClass class {}
4) class MyClass;
Answer : class MyClass {}
What is the output of cout << 5 * 3 + 2 << endl;
1) 15
2) 17
3) 20
4) None of the above
Answer : 17
Which operator is used for dynamic memory allocation in C++?
1) new
2) malloc
3) alloc
4) create
Answer : new
Which of the following is used to include a header file in C++?
1) #include
2) #include <filename>
3) include <filename>
4) import <filename>
Answer : #include <filename>