1. Which of the following is used for generic programming?
A. Virtual functions
B. Modules
C. Templates
D. Abstract Classes
Answer: C
Explanation:
Templates are used for generic programming. They help in making generic functions and classes hence achieving the generic codes.
2. Which of the following is correct about templates?
A. It is a type of compile time polymorphism
B. It allows the programmer to write one code for all data types
C. Helps in generic programming
D. All of the mentioned
Answer: D
Explanation:
Templates are used for generic programming hence allowing to write a single function for all data types. It is a type of compile time polymorphism.
3. How many components STL has?
A. 1
B. 2
C. 3
D. 4
Answer: D
Explanation:
STL has four components namely Algorithms, Containers, Functors and Iterators.
4. What are the containers?
A. Containers store objects and data
B. Containers stores all the algorithms
C. Containers contain overloaded functions
D. Containers contain set of Iterators
Answer: A
Explanation:
Containers is a component of STL which stores objects and data.
5. In how many categories, containers are divided?
A. 1
B. 2
C. 3
D. 4
Answer: D
Explanation:
Containers are divided into 4 categories namely Sequence Containers, Associative Containers, Unordered Associative Containers and Container Adaptors.
6. What are the Sequence Containers?
A. Containers that implements data structures which can be accessed sequentially
B. Containers that implements sorted data structures for fast search in O(logn)
C. Containers that implements unsorted(hasheD. data structures for quick search in O(1)
D. Containers that implements data structures which can be accessed non-sequentially
Answer: A
Explanation:
Sequence Containers is the subset of Containers that implements data structures which can be accessed sequentially.
7. How many Sequence Containers are provided by C++?
A. 2
B. 3
C. 4
D. 5
Answer: D
Explanation:
C++ provides 5 types of Sequence Containers namely array, vector, deque, forward_list and list.
8. What are the Associative Containers?
A. Containers that implements data structures which can be accessed sequentially
B. Containers that implements sorted data structures for fast search in O(logn)
C. Containers that implements unsorted(hasheD. data structures for quick search in O(1)
D. Containers that implements data structures which can be accessed non-sequentially
Answer: B
Explanation:
Associative Containers is the subset of Containers that implements sorted data structures for fast search in O(logn).
9. How many Associative Containers are provided by C++?
A. 2
B. 3
C. 4
D. 5
Answer: C
Explanation:
C++ provides 4 types of Associative Containers namely Set, Map, multiset and multimap.
10. What are Unordered Associative Containers?
A. Containers that implements data structures which can be accessed sequentially
B. Containers that implements sorted data structures for fast search in O(logn)
C. Containers that implements unsorted(hasheD. data structures for quick search in O(1)
D. Containers that implements data structures which can be accessed non-sequentially
Answer: C
Explanation:
Unordered Associative Containers is the subset of Containers that implements unsorted(hasheD. data structures for quick search in O(1) amortized O(n) Worst case complexity.
11. What are Container Adaptors?
A. Containers that implements data structures which can be accessed sequentially
B. Containers that implements sorted data structures for fast search in O(logn)
C. Containers that implements unsorted(hasheD. data structures for quick search in O(1)
D. Containers that provide a different interface for sequential containers
Answer: D
Explanation:
Container Adaptors is the subset of Containers that provides a different interface for sequential containers.
12. How many Container Adaptors are provided by C++?
A. 2
B. 3
C. 4
D. 5
Answer: B
Explanation:
C++ provides 3 types of Container Adaptors namely Stack, Queue and Priority Queues.
13. What are Iterators?
A. Iterators are used to iterate over C-like arrays
B. Iterators are used to iterate over pointers
C. Iterators are used to point memory addresses of STL containers
D. Iterators are used to iterate over functions
Answer: C
Explanation:
In C++, Iterators are provided to iterate over the STL containers.
14. How many types of Iterators are provided by C++?
A. 2
B. 3
C. 4
D. 5
Answer: D
Explanation:
There are five types of Iterators provided by C++ namely Input Iterators, Output Iterators, Forward Iterators, Bi-directional Iterators and Random-access Iterators.
15. Which header file is used for Iterators?
A. <iterator>
B. <algorithm>
C. <iter>
D. <loopIter>
Answer: A
Explanation:
Iterators are present inside the <iterator> header file so this header file is needed to use Iterators.