What does std::vector<int>::push_back do in C++?
Correct answer
D. Appends an element at the end, growing if needed
14 views
D. Appends an element at the end, growing if needed
14 views
push_back copies or moves a value into a new slot at the end and increases the size by one, reallocating when size reaches capacity. Because reallocation can move the buffer, iterators and references obtained earlier may be invalidated. reserve only changes capacity without changing size, and insert(begin(), x) is the operation that shifts elements to make room at the front.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.