R1 is a reference bound to 1

ri is a reference bound to i so how come it prints 10, 10 ?
1
2
3
  int i, &ri = i;
i = 5; ri = 10;
std::cout << i << " " << ri << std::endl;


ri refers to i so when you do ri = 10; you are setting the value of i to 10.
Last edited on
It's ri = 10 and nowhere it says i = ri
See that & on the first line? That means ri is a reference to i. You can think of ri as an alternative name for i. When you use ri in the code you are actually using i.
Topic archived. No new replies allowed.