For std::vector
, back()
returns a reference to the last element, so &collection.back()
is what you need.
In C++17, emplace_back
returns a reference to the new element. You could use it instead of push_back
:
vector<int> collection;
int *pointer = &collection.emplace_back(42);