In your case
char* s = "my String"
is legal and valid, because a representation like "my String"
is called a string literal and the representation essentially gives the address of the first element in the string, which is again a pointer to a char
. So, we can store that in another pointer to a char
.
The usability, is mostly same with char s[10] = "my string";
, except the fact that in former case, s
pointing to a string literal, you cannot (even attempt to) modify it. Trying so will invoke undefined behavior.