Practice 20 Templates & STL multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.
Show Answer & Explanation
Correct Answer: B — Generic programming
Templates enable generic programming - write once, use with any type.
Show Answer & Explanation
Correct Answer: B — template<typename T>
Template syntax: template<typename T> or template<class T>.
Show Answer & Explanation
Correct Answer: B — Standard Template Library
STL is Standard Template Library.
Show Answer & Explanation
Correct Answer: D — printf
printf is a C function, not an STL container.
Show Answer & Explanation
Correct Answer: B — Dynamic array
vector is a dynamic array that can grow in size.
Show Answer & Explanation
Correct Answer: B — Key-value pairs
map stores key-value pairs with unique sorted keys.
Show Answer & Explanation
Correct Answer: B — Traverse containers
Iterators are used to traverse STL containers.
Show Answer & Explanation
Correct Answer: B — Stores unique sorted elements
set stores unique elements in sorted order.
Show Answer & Explanation
Correct Answer: B — LIFO
STL stack follows LIFO (Last In First Out).
Show Answer & Explanation
Correct Answer: B — Specific implementation for a type
Template specialization provides specific implementation for particular types.
Show Answer & Explanation
Correct Answer: B — Sorted order
STL set stores unique elements in sorted order using balanced BST (usually Red-Black tree).
Show Answer & Explanation
Correct Answer: B — Key-value pairs in sorted order
STL map stores key-value pairs sorted by key, with unique keys.
Show Answer & Explanation
Correct Answer: B — Hash table
unordered_map uses hash table for O(1) average access time.
Show Answer & Explanation
Correct Answer: C — Insertion at both ends efficiently
Deque (double-ended queue) allows efficient insertion/deletion at both front and back.
Show Answer & Explanation
Correct Answer: B — Max-heap (largest first)
STL priority_queue is a max-heap by default; largest element has highest priority.
Show Answer & Explanation
Correct Answer: B — Generalized pointers to elements
Iterators are objects that point to elements in containers, providing uniform access.
Show Answer & Explanation
Correct Answer: B — O(n log n)
STL sort() uses Introsort with O(n log n) average and worst-case complexity.
Show Answer & Explanation
Correct Answer: B — Variable number of template parameters
Variadic templates accept variable number of template arguments using ... syntax.
Show Answer & Explanation
Correct Answer: B — List faster for middle insertion
List has O(1) insertion anywhere with iterator, vector has O(n) for middle insertion.
Show Answer & Explanation
Correct Answer: B — Deduces type automatically
auto keyword deduces type from initializer, simplifying iterator declarations.