const int a = 10;
int main()
{
int *p = &a;
*p = 100;
printf ("%d\n", *p);
}
The above code crashes, which is as per the expectation.
Now check the below code (Change the variable a
from global to local variable).
int main()
{
const int a = 10;
int *p = &a;
*p = 100;
printf ("%d\n", *p);
}
The code prints 100 as the output. My question is that why read-write access is allowed for the local const variable?