在以下程序中,相同的内存位置如何保持不同的值?我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
输出:
The value of i is:100
The value j holds:1
The address of i is:0xbffbe79c
The address of j is:0xbffbe79c
Run Code Online (Sandbox Code Playgroud)