工欲善其事 必先利其器
const int count = 3;
…
int *p = (int*)&count;
*p = 5;
cout << count << “ ” << *p << endl;
程序并不会报出编译错误,而且会打印出3 5,原因是count在预编译期间就会被替换成3,至于为什么可以修改常量的值,那是因为const *被强制转换成为了int *。
Copyright @ 2024 ldjhust Powered by .NET 9.0 on Kubernetes Powered by: .Text and ASP.NET Theme by: .NET Monster