HP C/iX Reference Manual (31506-90011)

26 Chapter2
Lexical Elements
String Literals
String Literals
A string literal is a sequence of zero or more characters enclosed in double quotation
marks.
Syntax
string-literal:
"
[s-char-sequence]
"
L"
[s-char-sequence]
"
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any character in the source character set except
double quote, backslash, or newline
escape-sequence
Description
You can type special characters in a character string literal using the escape sequence
notation described previously in the section on character constants. The double quote
character ( ' ) must be represented as an escape sequence if it is to appear inside a string
literal. Represent the string 'he said "hi"' with
"he said \"hi\""
A character string has static storage duration and type array of char.
The actual characters stored in a character string literal are the exact characters specified.
In addition, a null character (\0) is automatically added to the end of each character string
literal by the compiler. Note that the null character is added only to string literals. Arrays
of characters are not terminated with the extra character.
Character string literals that have no characters consist of a single null character.
Note that a string literal containing one character is not the same as a character constant.
The string literal "A" is stored in two adjacent bytes with the A in the first byte and a null
character in the second byte; however, the character constant 'A' is a constant with type
int and the value 65 (the ASCII code value for the letter A).
ANSI C allows the usage of wide string literals. A wide string literal is a sequence of zero
or more multibyte characters enclosed in double-quotes and prefixed by the letter L. A wide
string literal has static storage duration and type "array of wchar_t." It is initialized with
the wide characters corresponding to the given multibyte characters.
Examples
L"abc##def"