64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream >
using namespace std;
int main(void)
{
const int a=10;
int * p = (int*)&a;//为了能尝试通过*p修改常量a的值,用了强制转换
cout < <"a = " < < a < <endl; //输出 a = 10
cout < <"*p= " < <*p < <endl; //输出 *p = 10
*p=100; //试图修改a的值
cout < <"a = " < < a < <endl; //仍然输出: a = 10
cout < <"*p= " < <*p < <endl; //这里却输出: *p = 100
system("pause");
}