I am learning C++ and I have problem to understand why this works. I understand that a reference is just synonym for a certain object. But I do not understand why this
std::vector<int> v{1,2,3};
for (auto &i : v) //using reference
i *= i;
outputs 1,4,9
and this
std::vector<int> v{1,2,3};
for (auto i : v) //without using reference
i *= i;
outputs 1,2,3
?
Thank you in advance