I have this old fixed idea, probably acquired in the dawn ages of K&R, that something like
char *str = "123";
*str = '0';
is OK and will set *str to "023".
Clearly I am wrong, but I can't find anything in the C99 standard that says so.
I am aware that
char str[] = "123";
*str = '0';
works fine.
Given that pointer notation and array notation are two syntactic ways of performing the same semantic tasks,
why is one treated as a pointer to a const literal and the other treated as modifiable data?
I've looked in the C99 standard, but haven't found a good reference.
Have you one?
Start Free Trial