I have a pretty short question:
vector<int> ints{1,2,3,4}; int &y = ints[0];
Why during commenting you get 5, 2, 3, 4 , but when you uncomment ints.push_back(y); , you get 1, 2, 3, 4, 1 . I will write again to be completely clear about the problem: you get [-->1<--], 2, 3, 4, 1 instead of 5, 2, 3, 4, 1 or even 5, 2, 3, 4, 5
This behavior turns me on ... What happens under the hood?
source share