Because the compiler sees this
char myStrings[][20] = {"My 1st string", "My 2nd string", "My 3rd string"};
a
char myStrings[][20] = {(char*), (char*), (char*)};
Then, errrr ... hmmm, with "compiler magic", he can copy the characters in these (char*) to the array myStrings [0] and myStrings [1], ....
Edit
You cannot have jagged arrays in C. Suppose you have
char my_strings[][] = {"a", "ab", "abc", "foo foo fo foo foo", "abc", "ab", "a"};
my_strings[0] requires the same space as my_strings[3] , because the language requires the elements of the array to be contiguous, and it needs a specific size for each array.
my_strings in memory
'a' '\ 0' '\ 0' ... '\ 0' but must be a definite size
'a' 'b' '\ 0' ... '\ 0' definite size
...
'f' 'o' 'o' ... '\ 0'
...
To find the maximum size and initialize the array (s), the compiler needs to do two passes over string literals.
source share