Answer
Iterator invalidation means an operation makes an existing iterator, pointer, or reference no longer safely designate its former element. • Invalidation rules are specific to each container and operation. • A vector reallocation invalidates all iterators, pointers, and references to its elements. • Using an invalidated iterator has undefined behavior.
💡 C++ Example
std::vector<int> values;
values.reserve(2);
values.push_back(1);
auto iterator = values.begin();
values.push_back(2); // No reallocation because capacity was reserved.
⚡ Quick Revision
Check each container operation’s invalidation rules before reusing iterators.