This is just undefined behavior if we look in the section of the standard C99 project 6.7.3 Type 4 indentation, which says:
If an attempt is made to modify an object defined using the const type using an lvalue with a non-constant qualified type, the behavior is undefined. If an attempt is made to refer to an object defined using an unstable type by using the lvalue value with a non-volatile type, the behavior is undefined. 115)
Thus, you cannot have any expectations about the results, and you should not do this.
If we look at paragraph 2, he says:
Properties associated with qualified types make sense only for expressions that are lvalues. 114)
and footnote 114 says:
An implementation may place a const object that is not mutable in a read-only area of ββthe storage location. Moreover, an implementation should not allocate storage for such an object if its address is never used.
In the general case, an implementation is not required to make read-only constant variables, but it can, but since R .. indicates that an automatic variable in read-only memory will be difficult.
source share