Question 13
Back to Exercise
A program stores auto it = v.begin(); and then calls v.push_back(x);. Is it still valid?
- A Always
- B Not if the push_back reallocated – then all iterators, pointers and references to elements are invalid Correct
- C Only if v was empty
- D Iterators are never invalidated
Correct Answer: Option B
Reallocation moves the elements to a new buffer. Re-obtain iterators after growing, or reserve enough capacity first.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!