You mentioned
dereference pointer to constant data
So, consider the following code
#include <stdio.h> int main() { const int foo = 0xdead; int* bar = (int*) &foo; *bar = 0xcafe; printf("const int foo = %#x", foo); return 0; }
Output: const int foo = 0xcafe
In C, C ++ const is just a time compiler for variables. This means that the compiler does not want to change the value of const at compile time. At run time, there is no concept of const => all local variables are stored on the stack, all static and global variables are stored in the .data section. This way you can dereference a constant and change it only at runtime
source share