Character Array Initialization

In C++, when you initialize character arrays, a trailing ' \0' (zero of type char) is appended to the string initializer. You cannot initialize a character array with more initializers than there are array elements.

In ISO/ANSI C, space for the trailing '\0' can be omitted in this type of initialization.

The following initialization, for instance, is not valid in C++:

char v[3] = "asd"; // not valid in C++, valid in ISO/ANSI C

because four elements are required. This initialization produces an error because there is no space for the implied trailing '\0' (zero of type char).



Arrays