回复:(wangweicoin)[求助]关于const引用的问题
You can debug your program --- which may tell you why.
=======================================================
#include<iostream>
using namespace std;
int main()
{
/** test 1
In this test, &i != &r; i.e., memory
locations of the two variables are
different.
I don't know why this is happening.
*/
double i=45;
const int &r=i;
cout<<&i<<" "<<&r<<endl;
i=5;
i=6;
cout<<i<<" "<<r<<endl;
/** test 2
In this test, both i2 and r2 share the same
memory location.
*/
int i2=41;
const int &r2=i2;
cout<<&i2<<" "<<&r2<<endl;
i2=5;
i2=6;
cout<<i2<<" "<<r2<<endl;
return 0;
}