Two different values at the same memory address

前端 未结 7 651
春和景丽
春和景丽 2020-11-22 08:14

Code

#include 
using namespace std;

int main() {
    const int N = 22;
    int * pN = const_cast(&N);
    *pN = 33;
    co         


        
7条回答
  •  礼貌的吻别
    2020-11-22 08:42

    You can declare N as volatile, to force the compiler to fetch the current value from the variable's memory location.

    volatile const int N = 22;

提交回复
热议问题