|
|
|
|
|
by nequo
1140 days ago
|
|
I know. But my understanding was that `"xyz"` is an array of characters so that these two would have the same representation in memory: char word[] = {'x', 'y', 'z', '\0'}; // sizeof(word) = 4, sizeof(*word) = 1
char word[] = "xyz"; // sizeof(word) = 4, sizeof(*word) = 1
What I did not realize was that the above two are not the same as this: char *word = "xyz"; // sizeof(word) = 8, sizeof(*word) = 1
|
|
An initializer doesn't change that. It only affects the value stored in the object when it's created.
A special case exception is that an array object defined with empty square brackets gets its length from the initializer, so
is a shorthand for, and is exactly equivalent to: