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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -