c/language/string literal

Constructs an unnamed object of specified character array type in-place, used when a character string needs to be embedded in source code.

Syntax
where

@1@ character string literal: The type of the literal is, where is the size of the string in code units of the execution narrow encoding, including the null terminator. Each element in the array is initialized from the next character in  using the execution character set. @2@ UTF-8 string literal: The type of the literal is, where is the size of the string in UTF-8 code units including the null terminator. Each element in the array is initialized from the next multibyte character in  using UTF-8 encoding.

@5@ wide string literal: The type of the literal is, where is the size of the string in code units of the execution wide encoding, including the null terminator. Each element in the array is initialized as if by executing mbstowcs in implementation-defined locale.

Explanation
First, at (after macro expansion), the adjacent string literals (that is, string literals separated by whitespace only) are concatenated.

Secondly, at, a terminating null character is added to each string literal, and then each literal initializes an unnamed array with static and length just enough to contain the contents of the string literal plus one for the null terminator.

String literals are not modifiable (and in fact may be placed in read-only memory such as ). If a program attempts to modify the static array formed by a string literal, the behavior is undefined.

It is neither required nor forbidden for identical string literals to refer to the same location in memory. Moreover, overlapping string literals or string literals that are substrings of other string literals may be combined.

Example
{{example
 * code=
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include 

int main(void) {   char s1[] = "a猫🍌"; // or "a\u732B\U0001F34C" char8_t char s2[] = u8"a猫🍌"; char16_t s3[] = u"a猫🍌"; char32_t s4[] = U"a猫🍌"; wchar_t s5[] = L"a猫🍌"; setlocale(LC_ALL, "en_US.utf8"); printf(" \"%s\" is a char[%zu] holding     { ", s1, sizeof s1 / sizeof *s1); for(size_t n = 0; n < sizeof s1 / sizeof *s1; ++n) printf("0x%02X ", +(unsigned char)s1[n]); puts("}"); printf(   "u8\"%s\" is a char8_t[%zu] holding  { "    "u8\"%s\" is a char[%zu] holding     { ", s2, sizeof s2 / sizeof *s2); for(size_t n = 0; n < sizeof s2 / sizeof *s2; ++n) printf("0x%02X ", s2[n]); printf("0x%02X ", +(unsigned char)s2[n]); puts("}"); printf(" u\"a猫🍌\" is a char16_t[%zu] holding { ", sizeof s3 / sizeof *s3); for(size_t n = 0; n < sizeof s3 / sizeof *s3; ++n) printf("0x%04" PRIXLEAST16" ", s3[n]); puts("}"); printf(" U\"a猫🍌\" is a char32_t[%zu] holding { ", sizeof s4 / sizeof *s4); for(size_t n = 0; n < sizeof s4 / sizeof *s4; ++n) printf("0x%08" PRIXLEAST32" ", s4[n]); puts("}"); printf(" L\"%ls\" is a wchar_t[%zu] holding { ", s5, sizeof s5 / sizeof *s5); for(size_t n = 0; n < sizeof s5 / sizeof *s5; ++n) printf("0x%08X ", (unsigned)s5[n]); puts("}"); } "a猫🍌" is a char[9] holding     { 0x61 0xE7 0x8C 0xAB 0xF0 0x9F 0x8D 0x8C 0x00 } u8"a猫🍌" is a char[9] holding    { 0x61 0xE7 0x8C 0xAB 0xF0 0x9F 0x8D 0x8C 0x00 } u"a猫🍌" is a char16_t[5] holding { 0x0061 0x732B 0xD83C 0xDF4C 0x0000 } U"a猫🍌" is a char32_t[4] holding { 0x00000061 0x0000732B 0x0001F34C 0x00000000 } L"a猫🍌" is a wchar_t[4] holding { 0x00000061 0x0000732B 0x0001F34C 0x00000000 } }}
 * 1) if __STDC_VERSION__ >= 202311L
 * 1) else
 * 1) endif
 * 1) if __STDC_VERSION__ >= 202311L
 * 1) else
 * 1) endif
 * 1) if __STDC_VERSION__ >= 202311L
 * 1) else
 * 1) endif
 * p=true
 * output=