I always thought that an statement like const int *a
means a
is an int
pointer to const
data and as such one should not b
Casts usually suppress warnings. There is a gcc option, -Wcast-qual
that will warn you about casts that are losing a const
or volatile
qualifier.
The program ran successfully because the memory used to store the array wasn't actually readonly, because they were allocated on the stack. This is an implementation detail and technically your code could have crashed if the implementation was really strict.
Declare a
and b
as globals and there's a greater chance it will crash (still not a guarantee)