What happens to iterators when a std::vector reallocates during push_back?
- A They remain valid
- B All iterators, pointers and references into the vector are invalidated
- C Only end() is invalidated
- D They are automatically updated
Answer
All iterators, pointers and references into the vector are invalidated
Iterator invalidation is one of the most common sources of undefined behaviour. Reserving capacity in advance avoids reallocation.





