I'm trying to reference a certain index within a vector but whenever I add new items to the vector the pointer isn't pointing towards the original value.
The example I have is this:
std::vector<int> a;
a.push_back(1);
int* a_1 = &a[0];
a.push_back(2);
When I do:
int* a_1 = &a[0];
It's referencing the first value which is 1, but once I push a new item onto the vector the value becomes undefined. Why is my pointer becoming undefined once I push more items onto the vector?