CodeRigor

WEEKLY ENGINEERING PRACTICE

A handle across growth

A small reasoning exercise. Follow the behavior, choose an explanation and use the feedback to decide what to practice next.

Trace the behavior

After reserve returns successfully, what guarantee applies to saved? The requested capacity is larger than the old capacity.

C++
std::vector<int> values{10, 20};
const int* saved = &values[0];
values.reserve(values.capacity() + 1);
// Is saved still a valid pointer to the first element?

Choose your explanation