Yes, inside the string literal both values ββare the same.
A character literal requires an escaped version:
char x = '\'';
Standard links are two sources. First, the stages of translation. From C.11 and sect 5.1.1.2 (C ++. 11 [ lex.phases ] has a similar language):
- Each character set element and escape sequence in character constants and string literals is converted to the corresponding execution character set element ; if there is no corresponding element, it is converted to an element defined in the implementation that is different from the zero (wide) character.
The following is a grammar definition for a character constant and for string literals that allow escape sequences to be used. And a simple escape sequence is an escape sequence in a grammar. C.11 and section 6.4.4.4 defines it (C ++. 11 [ lex.ccon ] has the same definition):
simple escape sequence: one of
\' \" \? \\ \a \b \f \n \r \t \v
Finally, for string literals, the standard indicates that the interpretation of the characters in the literal is the same as each of them being a character constant, and then makes an exception. ' From C.11 and sect 6.4.5 (C ++. 11 [ lex.string ] has a similar language):
The same considerations apply to each element of a sequence in a string literal, as if it were in an integer character constant (for a character or UTF-8 string literal) or wide (for a wide string literal), except that the single quote ' equals represented either by itself or the escape sequence \' , but the double quote "must be represented by the escape sequence \" .
source share