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
c. X*
d. X&
2. Which classes allow primitive types to be accessed as objects?
a. Storage
b. Virtual
c. Friend
d. Wrapper
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++
a. float
b. string
c. int
d. wchar_t
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?
a. abstract
b. Virtual
c. Dynamic
d. Typeid
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)?
a. std::vector
b. std::list
c. std::map
d. std::set
16. Which of the following is not a standard exception built in C++.
a. std::bad_creat
b. std::bad_alloc
c. std::bad_cast
d. std::bad_typeid
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++
a. Explicit
b. Public
c. Implicit
d. Private
20. Each pass through a loop is called a/an
a. enumeration
b. iteration
c. culmination
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++.
Patiwet says
9. Which of the following is not true about preprocessor directives
a. They begin with a hash symbol (correct)
b. They are processed by a preprocessor (correct)
c. They form an integral part of the code (correct)
d. They have to end with a semi colon (incorrect)
The answer of number 9 must be d. not a.
Amir Ali says
Yes D is correct
Patiwet says
The answer of question number 20 is b. not c.
c++\\ says
The answer of question number 12 is b. not d.
Tahir says
Bullshit So many mistakes in this MCQ.
Marwa says
13. What’s wrong? for (int k = 2, k <=12, k++)
a. the increment should always be ++k. (correct)
b. the variable must always be the letter i when using a for loop. (correct)
c. there should be a semicolon at the end of the statement. (correct)
d. the commas should be semicolons. (incorrect)
The answer of number 13 must be d. not b.
Ankit Rastogi says
Which of the following is a valid destructor of the class name “Country”
b. void Country() incorrect
d. void ~Country(). Correct
In answer b option is correct why??
Please Explain