相同的内存位置如何在以下程序中保存不同的值?我正在使用 g++ 编译器。
代码:
#include<iostream>
using namespace std;
int main()
{
const int i=100;
int *j = const_cast<int*>(&i);
*j=1;
cout<<"The value of i is:"<<i<<endl;
cout<<"The value j holds:"<<*j<<endl;
cout<<"The address of i is:"<<&i<<endl;
cout<<"The address of j is:"< <j<<endl;
}
输出:
The value of i is:100
The value j holds:1
The address of i is:0xbffbe79c
The address of j is:0xbffbe79c