The first one is writable memory allocated specifically for arr
, which is an array of char
s. You can modify it without invoking undefined behavior. This is completely legal:
char arr[] = "Hello, world!";
arr[1] = 'i';
The second one is a pointer to a read-only string. Therefore, this is undefined behavior:
char *parr = "Hello, world!";
parr[1] = 'i'; // Cannot write to read-only memory!
In some compiler implementations:
char *a = "Hello, world!";
char *b = "Hello, world!";
a[1] = 'i';
// b[1] == 'i';
This isn't guaranteed - I'm only including it to give you an 'intuitive' feel of why it's undefined behavior.