#include <iostream>
using namespace std;
int main()
{
int i=9,k=8;
int &q=i;
q=k;
cout<<i<<"\n"<<q<<"\n";
return 0;
}
Output:
8
8
But in my book it is given "q=k changes only the value of i and not q. This is because q being a reference gets de-referenced automatically as(*q). Hence the value at the address stored in q is replaced by value of i" But as you can see value of q also gets changed. Isn't it wrong???