I know in C we can modify the 'const int' via pointer. But while compiling the program I enabled the '-O2' flag in gcc, and const int can't modify the value, so just wanted to know how gcc optimization flag affect the modifying 'const int'.
Here is the sample application test.c
#include <stdio.h>
#include <stdlib.h>
int main(int ac, char *av[])
{
const int i = 888;
printf("i is %d \n", i);
int *iPtr = &i;
*iPtr = 100;
printf("i is %d \n", i);
return 0;
}
gcc -Wall -g -o test test.c
./test
i is 888
i is 100
gcc -Wall -g -O2 -o test test.c
i is 888
i is 888
This curiosity leads me to write this question.