C++ CPP case studies
C++ CPP · Put your knowledge to work in context.
This independent study page provides practice for C++ CPP. Its editorial learning areas include C++ standard containers, iterators and algorithm contracts; C++ templates, callable objects, streams and exceptions; C++ types, expressions, functions and control flow; C++ object lifetime, ownership, classes and polymorphism. The questions develop subject knowledge and application through worked reasoning, distinctions between competing answers, and practical scenarios. Study the relevant guide before attempting a mixed set, then explain the evidence or calculation that supports each answer. Topics on this exam: C++ standard containers, iterators and algorithm contracts, C++ templates, callable objects, streams and exceptions, C++ types, expressions, functions and control flow, and C++ object lifetime, ownership, classes and polymorphism. The C++ CPP case studies are 4 cases and about 706 words.
1Reserve does not create ten elements
A fictional C++ exercise starts with an empty vector and calls reserve with an argument of ten. A learner claims the vector now contains ten initialized elements and that its reported capacity must equal exactly ten on every conforming implementation. Another reads the capacity and size contracts separately and asks how a later indexed write would be justified. The exercise supplies no element insertion or resizing operation.
179 words, under 1 min2A mutable captured copy and the original variable
A fictional program initializes an integer counter and creates a lambda capturing that counter by value. The lambda is mutable and increments its captured value each time it is called. The study record distinguishes the enclosing variable from the closure object, and repeated calls use the same closure instance. A colleague says mutable makes the capture an alias for the original counter and therefore every call must change the enclosing variable.
176 words, under 1 min3An observed output is not a language guarantee
A fictional learner evaluates two expressions in a C++ study exercise. The first divides two positive integers with a declared floating-point conversion before the division. The second modifies the same scalar object in two unsequenced operands of addition. A colleague runs both programs once and proposes recording the observed output as a guaranteed portable result for each.
175 words, under 1 min4Virtual dispatch does not repair invalid deletion
A fictional code review finds a base class with a virtual display function but no virtual destructor. A dynamically allocated derived object is stored through a base pointer. The display call selects the expected derived implementation, after which the program deletes through that base pointer. A colleague declares the program correct because the first printed word matched the intended answer.
176 words, under 1 min