这是我的测试代码:
#define print(A) cout << #A << " = " << A << endl;
int main()
{
const int e = 2;
int *p = (int *)&e;
*p = 4;
print(e);
print(*p);
print(&e);
print(p);
}
结果:
e = 2;
*p = 4;
&e = 0xbfc6b458;
p = 0xbfc6b458;
既然“p”按照相同的地址指向“e”,那么*p和“e”怎么会不同???这可能很危险,对吧?