Answers to C++ Multiple Choice Questions Set 1
These are the answers to Multiple Choice Questions Set – 1 from C++. Click here to go to Questions page.
1. Which of the following languages is a subset of C++ language?
Answer: A. C Language
C programs are also C++ programs. Hence C is a suset of C++
2. Which of the following correctly describes C++ language?
Answer: A. Statically typed langauge
All the types and type related information in programs are statically resolved by a compiler in compile time. Hence C++ is a statically typed language.
3. Which of the following keyword supports dynamic method resolution?
Answer: B. Virtual
The virtual keyword indicates that the virtual method will be resolved at runtime (i.e., the method resolution is dynamic).
4. Which of the following language is not supported by C++?
Answer: B. Reflection.
C++ does not have any support for reflection (reflection requires extensive runtime support, which is not available since it is a natively compiled language).
5. Which of the following language feature is not an access specifier in C++?
Answer: D. Internal
All other public, private and protected are access specifier in C++
6. What does STL stand for?
Answer: STL stands for Standard Template Library
The Standard Template Library (STL) is a software library partially included in the C++ Standard Library. It provides containers, iterators, algorithms, and functions.
7. Which of the following is the most common way of implementing C++?
Answer: A. C++ programs are directly compiled into native code by a compiler
8. What is the implicit pointer that is passed as the first argument for nonstatic member functions?
Answer: D. ‘this’ pointer
9. If X is the name of the class, what is the correct way to declare copy constructor of X?
Answer: D. X(const X& arg)
The copy constructor takes a const reference to the class type as the argument.
10. Which of the following operator cannot be overloaded?
Answer: D. :: (scope resolution operator)
Other three operators can be overloaded.
11. Which of the following operators can be overloaded?
Answer: B. & (address-of operator)
member access operator, sizeof and conditional operators can not be overloaded.
12. How do we declare an abstract class?
Answer: A. By providing at least one pure virtual method (function signature followed by ==0)
Note that ‘abstract’ is not a keyword in C++
13. How do we declare an ‘interface’ class?
Answer: A. By making all the methods pure virtual in a class
C++ does not support interface classes (as in Java) directly as a language feature. However, we can create interface class by making all the methods in the class pure virtual.
14. How many copies of a class static member are shared between objects of the class?
Answer: A. A copy of the static member is shared by all objects of a class
Static members are not associated with objects, but are associated with the class. Storage for static members is allocated for teh class even if there are no instances created for that class
15. Which of the following is true about const member functions?
Answer: A. const members can be invoked on both const as well as nonconst objects.
Whereas, nonconst members can not be invoked on const object (and naturally, can be invoked only on nonconst objects)
16. When is std::bad_alloc exception thrown?
Answer: A. When new operator can not allocate memory
17. Which header file should we include for using std::auto_ptr?
Answer: A. <memory>
18. STL is based on which of the following programming paradigms?
Answer: C. Functional Programming
STL is based on the functional programming approach. Note that it is not based on OOP though it is part of the standard library of C++
19. Which of the following correctly describes the meaning of ‘namespace’ feature in C++?
Answer: D. Namespace provide facilities for organizing the names in a program to avoid name clashes.
Namespaces can be thought of as ‘named scopes’. Specifically, they have nothing to do with memory area required for storing names.
20. Which of the following is the most general exception handler that catches exception of any type?
Answer: C. catch(…)
The catch with ellipsis (…) is a general exception handler that can handle any exception that is thrown from the try block. Note that std::exception handles all the exceptions derived from that type, but does not handle exception of any other type not deriving from it or primitive type exceptions.
These were the answers to Multiple Choice Questions Set – 1 from C++. Click here to go to Questions page.
Related posts:

[...] Studies « Linked List Data Structure in C++ Answers to C++ Multiple Choice Questions Set 1 [...]
[...] C++ Multiple Choice Questions Set 1 was posted on Monday, June 7th, 2010 and is filed under Multiple Choice Questions. You can click here to go to Questions of Set 1 and the Answers of Set 1. [...]