ILE C/C++ Programmer's Guide


Initializing Character Arrays

C++ language onlyIn 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.

C language onlyIn ISO C, space for the trailing '\0' can be omitted in this type of information.

For example, the following initialization is not valid in C++:

char v[3] = "asd"; //not valid in C++, valid in ISO 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). The following initialization, for instance, is valid in C++:

char v[4] = "asd"; //valid in C++
Note:
For more detailed information on compatibility, see WebSphere Development Studio: ILE C/C++ Language Reference.


[ Top of Page | Previous Page | Next Page | Table of Contents ]