According to this question you can't change what a reference refers to. Likewise the C++ Primer 5th Edition states
Once we have defined a reference, there is no way to make that reference refer to a different object. When we use a reference, we always get the object to which the reference was initially bound.
However the following code compiles and prints the value 4 which looks to me like the reference was changed?? Please elaborate if this is or is not so.
int a = 2;
int b = 4;
int &ref = a;
ref = b;
cout << ref;