Skip to main content
Journey Uncommon Logo
JourneyUncommon
easyC++vector basicsSingle-choice MCQ

Why can holding a reference or pointer to a `std::vector` element across a `push_back` be a bug?

std::vector<int> v = {1, 2, 3}; int& ref = v[0]; v.push_back(4); // may reallocate std::cout << ref; // safe?