On Feb 20, 1:42 pm, Richard Heathfield <r...@see.sig.invalidwrote:
suresh shenoy said:
I know that
char s[100];
s = "xyz";
is invalid and should use char ptr or string library to store a string
literal in s. Can anyone be precise why the second line is invalid?
char s[100] = "xyz";
The contents of s are now 'x', 'y', 'z', and 97 '\0's.
Just wanted to mention why this happends;
In array initialization, when the initialization does not initialize
all the elements of the array, the rest are given the value 0 (or NULL
in pointer context)
Notice, I said the rest; which means int foo[3] = { [1] = 42 };
guarantees foo[0] to be 0.