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 .

The concatenation of a wide string literal and narrow string literal is not supported in ILE C/C++. If a wide string literal and a narrow string literal are adjacent, as in the following:

"hello " L"there"   

the compiler will issue an error message.

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"  */


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