02/21/00
COM1100 Winter2000 Yuhong Yin
13
Character array initialization
nIf I want to declare a character array and initialize it, there are normally three ways:
nchar codes[6] = {‘s’, ’a’, ’m’, ’p’, ’l’, ’e’}
nSize is 6
nchar codes[]   = {‘s’, ’a’, ’m’, ’p’, ’l’, ’e’}
nSize is 6
nchar codes[] = “sample”; //no braces or commas
nSize is 7
nWe can use the string “sample” to initialize the codes array. This declaration created an array named codes having 7 elements. The last one is \0, also called null character. The null character is automatically appended to all strings by the C++ compiler.
n