What is the difference between these two definitions?
char *string = "MyString";
char string[] = "MyString";
As much as I know, the first one is a pointer to a string.
What is the difference between these two definitions?
char *string = "MyString";
char string[] = "MyString";
As much as I know, the first one is a pointer to a string.
The first is a pointer to a string literal, the second is an array initialized with the contents of the string literal (which BTW when optimized points exactly to where string
points).
The first one lives in the read only segment of the program's memory and thus cannot be modified.
The second one is an array of 9 elements and you can modify any of the 9 elements including the termnating null
byte that is not explicitly set in the code in your question.