The first is the writable memory allocated specifically for arr , which is an array of char s. You can change it without invoking undefined behavior. This is completely legal:
char arr[] = "Hello, world!"; arr[1] = 'i';
The second is a read-only string pointer. Therefore, this behavior is undefined:
char *parr = "Hello, world!"; parr[1] = 'i';
In some compiler implementations:
char *a = "Hello, world!"; char *b = "Hello, world!"; a[1] = 'i';
This is not guaranteed . I just turn it on to give you an βintuitiveβ idea of ββwhy this behavior is undefined.
source share