String concatenation
Another way to continue a string is to have two or more consecutive
strings. Adjacent string literals will be concatenated to produce
a single string. For example:
"hello " "there" /* is equivalent to "hello there" */
"hello" "there" /* is equivalent to "hellothere" */
Characters in concatenated strings remain distinct. For example,
the strings "\xab"
and "3"
are concatenated
to form "\xab3"
. However, the characters \xab
and 3
remain
distinct and are not merged to form the hexadecimal character \xab3
.
If a wide string literal and a narrow string literal are adjacent,
as in the following:
"hello " L"there"
the
result is a wide string literal. Note:
In
C99, narrow strings can be concatenated with wide string literals.
In
C++0x, the changes to string literal concatenation in the C99 preprocessor
are adopted to provide a common preprocessor interface for C and C++
compilers. Narrow strings can be concatenated with wide string literals
in C++0x. For more information, see C99 preprocessor features adopted in C++11 (C++11).


Following any concatenation, '\0' of type
char
is
appended at the end of each string. For a wide string literal, '\0'
of
type wchar_t
is appended. C++ programs find the end
of a string by scanning for this value. For example: char *first = "Hello "; /* stored as "Hello \0" */
char *second = "there"; /* stored as "there\0" */
char *third = "Hello " "there"; /* stored as "Hello there\0" */