While reading this question I wanted to test the input in GCC to see what errors would be output. To my surprise the following line:
char array[] = {"s"};
compiles without error or warning, resulting in an array of size 2 containing "s\0". I would have expected a compiler error because the right side of the expression is of type char*[].
Is an array initialization with only one element not treated as an array in this case, and why?
is same as:
Here
{ }are optional in this case because “s” is string literal.Or,
In this case,
{ }are necessary to initialize the array.