c - How does the system knew that an address being accessed is constant or not -
writing constant variable using pointer giving run time error.
const int i; int *p; void main() { p = (int*)&i; *p = 10; // causes runtime error }
but in windows system running ram itself.
when printed address of const variables , normal variables, can see in different offsets.
how system know address being accessed pointer const
one?
strictly speaking, code yields undefined behavior according c-language standard.
in practice, linker has placed variable i
in ro section of executable image.
so write-operation *p = 10
resulted in memory-access violation (aka segmentation fault).
Comments
Post a Comment