There is no such thing as an "enhanced for loop". This is a "range-for loop":
for (int i : iArr)
cout << &i << " ";
It gives you a different address because int i : iArr
is creating a copy of every element of iArr
and assigning it to i
.
If you want to refer to the original elements, you should use
for (int& i : iArr)
cout << &i << " ";