首页 > > > 关于C++ const 变量存储位置的问题
1 #include <iostream>
2 #include<climits>
3
4 using namespace std;
5
6 int main()
7 {
8 const int a = 3;
9
10 void* p = NULL;
11 p = (void*)&a;
12
13 *( (int*)p ) = 1;
14
15 cout<< "P址:" << p << "值:" << *( (int*)p )
16 << endl
17 << "a址:" << &a << "值:" << a
18 << endl;
19
20 cin.get();
21
22 return 0;
23 }源码如上,运行结果如下:

求教遇到过这种问题的大神,这是什么原理?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4594/viewspace-3129073/ ,如需转载,请注明出处,否则将追究法律责任。