Is this undefined behavior with const_cast? [duplicate]
问题 This question already has an answer here: behavior of const_cast in C++ [duplicate] 3 answers What is happening here? const int a = 0; const int *pa = &a; int *p = const_cast<int*>(pa); *p = 1; // undefined behavior ?? cout << a << *p; // ?? My compiler outputs 0 and 1, but address of \'a\' and value of \'p\' is the same, so I\'m confused how is this possible. 回答1: Quote from cppreference: Even though const_cast may remove constness or volatility from any pointer or reference, using the