C 字符串文本C String Literals

“字符串文本”是封闭在双引号 (" ") 内的源字符集中的字符序列。A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). 字符串用于表示可一起构成以 null 结尾的字符串的字符序列。String literals are used to represent a sequence of characters which, taken together, form a null-terminated string. 必须在宽字符串文本前添加字母 L 作为前缀。You must always prefix wide-string literals with the letter L.


" s-char-sequence opt"" s-char-sequence opt"

L" s-char-sequence opt"L" s-char-sequence opt"


s-char-sequence s-chars-char-sequence s-char

除双引号 (")、反斜杠 (\) 或者换行符以外的任何源字符集成员any member of the source character set except the double quotation mark ("), backslash (\), or newline character


以下示例是一个简单的字符串:The example below is a simple string literal:

char *amessage = "This is a string literal.";  

转义序列表中列出的所有转义码在字符串文本中均有效。All escape codes listed in the Escape Sequences table are valid in string literals. 若要表示字符串文本中的双引号,请使用转义序列 \"。To represent a double quotation mark in a string literal, use the escape sequence \". 可在不使用转义序列的情况下表示单引号 (')。The single quotation mark (') can be represented without an escape sequence. 反斜杠 (\) 在字符串中出现时必须后跟另一个反斜杠 (\\)。The backslash (\) must be followed with a second backslash (\\) when it appears within a string. 当反斜杠出现在行的末尾时,始终解释为行继续符。When a backslash appears at the end of a line, it is always interpreted as a line-continuation character.

另请参阅See Also

C 的元素Elements of C