As others have said, const tracked by the compiler in the same way that the compiler tracks the fact that the variable is int . In fact, I read that at least gcc considers const int different type from int , so it is not even tracked as a modifier, it tracks the same as int .
Note that you can actually change the value of const using a pointer cast, but the result is undefined:
#include <stdio.h> #include <stdlib.h> int main(void) { const int c = 0; printf("%d\n", c); ++*(int*)&c; printf("%d\n", c); }
On my machine using gcc this prints
0 1
But compiling with g ++ gives
0 0
Kevin
source share