I don't quite understand why the output on this is 10 10 if ri is a reference to i...
int i, &ri = i;
i = 5;
ri = 10;
std::cout << i << " " << ri << std::endl;
Could someone clear this up for me?
Similarly,
int i = 0, &r1 = i;
double d = 1, &r2 = d;
r2 = r1;
std::cout << r2; // output 0
i = r2;
std::cout << i; // output 0
r1 = d;
std::cout << r1; // output 0
If i = r2 and r2 is a refrence to d when d = 1, why isn't the ouput 1? Also, when r1 = d, why isn't the output 1 as well?