OOP with C++

Templates & STL — Practice MCQs for CCAT

20 Questions Section B: Programming OOP with C++

Practice 20 Templates & STL multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.

Q1.
Template provides:
ARuntime polymorphism
BGeneric programming
CMultiple inheritance
DEncapsulation
Show Answer & Explanation

Correct Answer: B — Generic programming

Templates enable generic programming - write once, use with any type.

Q2.
Function template starts with:
Ageneric
Btemplate<typename T>
Ctype T
Dclass T
Show Answer & Explanation

Correct Answer: B — template<typename T>

Template syntax: template<typename T> or template<class T>.

Q3.
STL stands for:
ASimple Template Library
BStandard Template Library
CSystem Template Library
DStatic Type Library
Show Answer & Explanation

Correct Answer: B — Standard Template Library

STL is Standard Template Library.

Q4.
Which is NOT an STL container?
Avector
Blist
Carray
Dprintf
Show Answer & Explanation

Correct Answer: D — printf

printf is a C function, not an STL container.

Q5.
vector in STL is:
AStatic array
BDynamic array
CLinked list
DStack
Show Answer & Explanation

Correct Answer: B — Dynamic array

vector is a dynamic array that can grow in size.

Q6.
map in STL stores:
AOnly keys
BKey-value pairs
COnly values
DIntegers only
Show Answer & Explanation

Correct Answer: B — Key-value pairs

map stores key-value pairs with unique sorted keys.

Q7.
Iterator is used to:
ADelete containers
BTraverse containers
CCreate containers
DSort only
Show Answer & Explanation

Correct Answer: B — Traverse containers

Iterators are used to traverse STL containers.

Q8.
set in STL:
AAllows duplicates
BStores unique sorted elements
CIs unsorted
DUses key-value
Show Answer & Explanation

Correct Answer: B — Stores unique sorted elements

set stores unique elements in sorted order.

Q9.
stack in STL uses:
AFIFO
BLIFO
CRandom
DPriority
Show Answer & Explanation

Correct Answer: B — LIFO

STL stack follows LIFO (Last In First Out).

Q10.
Template specialization is:
AGeneric version
BSpecific implementation for a type
CError
DNot allowed
Show Answer & Explanation

Correct Answer: B — Specific implementation for a type

Template specialization provides specific implementation for particular types.

Q11.
STL set stores elements in:
AInsertion order
BSorted order
CRandom order
DReverse order
Show Answer & Explanation

Correct Answer: B — Sorted order

STL set stores unique elements in sorted order using balanced BST (usually Red-Black tree).

Q12.
STL map stores:
AOnly values
BKey-value pairs in sorted order
COnly keys
DUnsorted pairs
Show Answer & Explanation

Correct Answer: B — Key-value pairs in sorted order

STL map stores key-value pairs sorted by key, with unique keys.

Q13.
unordered_map uses:
ABinary tree
BHash table
CLinked list
DArray
Show Answer & Explanation

Correct Answer: B — Hash table

unordered_map uses hash table for O(1) average access time.

Q14.
STL deque allows:
AOnly front insertion
BOnly back insertion
CInsertion at both ends efficiently
DNo insertion
Show Answer & Explanation

Correct Answer: C — Insertion at both ends efficiently

Deque (double-ended queue) allows efficient insertion/deletion at both front and back.

Q15.
STL priority_queue default order:
AMin-heap (smallest first)
BMax-heap (largest first)
CFIFO
DLIFO
Show Answer & Explanation

Correct Answer: B — Max-heap (largest first)

STL priority_queue is a max-heap by default; largest element has highest priority.

Q16.
Iterators in STL are:
AInteger indices
BGeneralized pointers to elements
CArray names
DFunction pointers
Show Answer & Explanation

Correct Answer: B — Generalized pointers to elements

Iterators are objects that point to elements in containers, providing uniform access.

Q17.
STL algorithm sort() complexity:
AO(n)
BO(n log n)
CO(n²)
DO(log n)
Show Answer & Explanation

Correct Answer: B — O(n log n)

STL sort() uses Introsort with O(n log n) average and worst-case complexity.

Q18.
Template parameter pack (variadic templates):
AFixed number of parameters
BVariable number of template parameters
CNo parameters
DOnly type parameters
Show Answer & Explanation

Correct Answer: B — Variable number of template parameters

Variadic templates accept variable number of template arguments using ... syntax.

Q19.
STL list vs vector for insertion:
AVector faster everywhere
BList faster for middle insertion
CSame performance
DNeither supports insertion
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.

Q20.
auto keyword with STL:
ACreates automatic variable
BDeduces type automatically
CMakes variable constant
DCreates global variable
Show Answer & Explanation

Correct Answer: B — Deduces type automatically

auto keyword deduces type from initializer, simplifying iterator declarations.