Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

What happens to iterators when a std::vector reallocates during push_back?

  1. A They remain valid
  2. B All iterators, pointers and references into the vector are invalidated
  3. C Only end() is invalidated
  4. 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.

All C++ MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as