, . .
char str[] = {'h','e','l','l','o',' ','w','o','r','l','d','\0'};
str
- , . str
. -
char *str = "hello word";
str
, . , .
, C ++ . ISO/IEC 14882: 2003 (E), 8.5.2
1. A char array (whether plain char, signed char, or unsigned char) can be
initialized by a string- literal (optionally enclosed in braces); a wchar_t
array can be initialized by a wide string-literal (option- ally enclosed in
braces); successive characters of the string-literal initialize the members of
the array.
[Example:
char msg[] = "Syntax error on line %s\n"; shows a character array
whose members are initialized with a string-literal. Note that because
ā\nā is a single character and because a trailing ā\0ā is appended,
sizeof(msg) is 25.
]
2. There shall not be more initializers than there are array elements.
[Example:
char cv[4] = "asdf" ;
]
, 2 .