Search code examples
c++cescapingstandardslanguage-specifications

Is "'" identical to "\'" as per the C/C++ standard?


int main()
{
    char* str1 = "Tom's cat";
    char* str2 = "Tom\'s cat";
}

The code can be compiled with VS 2015.

I just wonder:

Are both of the two ways compliant to the C and/or the C++ standard?


Solution

  • From the C++11 ISO Standard

    § 2.14.5 String Literals [lex.string]

    ...

    15 Escape sequences and universal-character-names in non-raw string literals have the same meaning as in character literals (2.14.3), except that the single quote ’ is representable either by itself or by the escape sequence \’