姬長信(Redy)

c – 这是const_cast的未定义行为吗?


参见英文答案 > behavior of const_cast in C++ ????????????????????????????????????3个
这里发生了什么?
const int a = 0;
const int *pa = &a;

int *p = const_cast(pa);
*p = 1;  // undefined behavior ??
cout << a << *p;  // ??

我的编译器输出0和1,但’a’的地址和’p’的值是相同的,所以我很困惑这是怎么回事.