latency.lab
Milestone Exam II

Memory · Moves · The STL

Covers: Modules 05–08Pass: 75%Rule: closed-book

Before you start

Milestone Exam II

12 questions · pass at 75%

Q01
std::move performs:
Whystd::move is only a cast; the move constructor/assignment does the actual stealing.
Q02
You define a destructor with delete[] but not a copy constructor. Copying an instance causes:
WhyDefault shallow copy shares the pointer; both destructors free it. Rule of Five.
Q03
The Rule of Zero says:
WhyHold vector/unique_ptr members and let the defaults do copy/move/destroy correctly.
Q04
unique_ptr is move-only because:
WhyExclusive ownership can't be duplicated; it can only transfer via move.
Q05
A reference cycle between two shared_ptrs results in:
WhyCounts never hit zero; break the cycle with weak_ptr.
Q06
Which container gives O(1) average key lookup with no ordering?
Whyunordered_map is a hash table, O(1) average.
Q07
A vector reallocation invalidates:
WhyGrowth moves the whole buffer, invalidating everything pointing into it.
Q08
Erasing one element from a std::map invalidates:
WhyNode-based containers invalidate only the erased node's iterator.
Q09
The order book uses std::map for each side because:
WhyMatching constantly needs the best price; a sorted map exposes it at begin().
Q10
Ranges in the STL are:
WhyHalf-open: begin included, end excluded. end() is a non-dereferenceable sentinel.
Q11
std::lower_bound requires the range to be ___ and runs in ___:
WhyBinary search needs a sorted range; it is O(log n) and returns the first element >= value.
Q12
A lambda that captures by reference and outlives the captured variable:
WhySame lifetime bug as any dangling reference, now hidden in a callable. Capture by value if it may outlive the scope.
+ Note