C++ Multiple Choice Questions
1. If the class name is X, what is the type of its “this” pointer (in a nonstatic, non-const member function)?
a. const X* const
b. X* const
2. Which classes allow primitive types to be accessed as objects?
3. When is std::bad_alloc exception thrown?
a. When new operator cannot allocate memory
b. When alloc function fails
c. When type requested for new operation is considered bad, thisexception is thrown
d. When delete operator cannot delete the allocated (corrupted) object
4. Which one of the following is not a fundamental data type in C++
5. Which of the following is a valid destructor of the class name “Country”
a. int ~Country()
b. void Country()
c. int ~Country(Country obj)
d. void ~Country()
6. Which of the following correctly describes C++ language?
a. Statically typed language
b. Dynamically typed language
c. Both Statically and dynamically typed language
d. Type-less language
7. Which of the following keyword supports dynamic method resolution?
8. Which of the following is the most preferred way of throwing and handling exceptions?
a. Throw by value and catch by reference.
b. Throw by reference and catch by reference.
c. Throw by value and catch by value
d. Throw the pointer value and provide catch for the pointer type.
9. Which of the following is not true about preprocessor directives
a. They begin with a hash symbol
b. They are processed by a preprocessor
c. They form an integral part of the code
d. They have to end with a semi colon
10. What’s wrong? while( (i < 10) && (i > 24))
a. the logical operator && cannot be used in a test condition
b. the while loop is an exit-condition loop
c. the test condition is always false
d. the test condition is always true
11. A continue statement causes execution to skip to
a. the return 0; statement
b. the first statement after the loop
c. the statement following the continue statement
d. the next iteration of the loop
12. What’s wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);
a. the question mark should be an equal sign
b. the first semicolon should be a colon
c. there are too many variables in the statement
d. the conditional operator is only used with apstrings
13. What’s wrong? for (int k = 2, k <=12, k++)
a. the increment should always be ++k
b. the variable must always be the letter i when using a for loop
c. there should be a semicolon at the end of the statement
d. the commas should be semicolons
14. Which of the following is not recommended in a header file?
a. Type definitions (typedefs)
b. Class definitions
c. Function definitions
d. Template definitions
15. Which of the STL containers store the elements contiguously (in adjacent memory locations)?
16. Which of the following is not a standard exception built in C++.
17. What does STL stand for?
a. Simple Template Library
b. Standard Template Library
c. Static Type Library
d. Single Type-based Library
18. What is the difference between overloaded functions and overridden functions?
a. Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
b. Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called an overloaded function.
c. Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding
d. Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden function.
19. Which one of the following is not a valid reserved keyword in C++
20. Each pass through a loop is called a/an
d. pass through
Correct Answers to C++ MCQ Questions
|1 – d||2 – b||3 – d||4 – a||5 – b||6 – d||7 – a||8 – b||9 – a||10 – d|
|11 – c||12 – d||13 – b||14 – d||15 – c||16 – a||17 – b||18 – b||19 – c||20 – c|
Thank you Rasel for pointing out the mistake. Answer for Q.No. 17 is updated accordingly.
Please, let us know if you discover any error or mistake in these MCQ sets. Don’t hesitate to leave your comments.
Download MCQ Questions PDF File for C++
Please visit Downloads section to download the pdf file of these MCQs from C++.