Following example added confusion in my understanding. I'm unable to understand how is it possible to modify the const variable local. Please help me to understand the same.
/* Compile code without optimization option */
// volatile.c
#include <stdio.h>
int main(void)
{
const int local = 10;
int *ptr = (int*) &local;
printf("Initial value of local : %d
", local);
*ptr = 100;
printf("Modified value of local: %d
", local);
return 0;
}
$ gcc volatile.c -o volatile –save-temps
$ ./volatile
Initial value of local : 10
Modified value of local: 100
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…