#include <iostream>
using namespace std;
int main()
{
int *p;
const int DATA = 100;
p = (int*) &DATA; //(int*) 此处需要强制类型转换 因为&DATA的类型为const int*
cout << "Old *P is " << *p << endl;
*p = 10;
cout << "DATA is " << DATA << endl;
cout << "New *P is " << *p << endl;
return 0;
}
Dev C++上
运行结果如下:
Old *P is 100
DATA is 100
New *P is 10
Process exited after 0.2883 seconds with return value 0
请按任意键继续…
由结果可以看出,虽然DATA所占的地址的值发生改变,但是DATA的值并没有改变。