Блог пользователя shuneo

Автор shuneo, история, 21 месяц назад, По-английски
char c = '"';
// it is compiled and successed.

I have a question that: why we can char c = '"'; instead of using char c = '\"'.

I used to think that char c = '"' is wrong before.

Thank you alot

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
21 месяц назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

Because standard says so. And it always was that way.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf (Section 5.3.13)

»
21 месяц назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

We don't need to escape the character " when we put it between '. The reason is just the compiler will understand it and there is no need for \.

But when we put it between " we need to escape it because if we don't it will be marked as the end of the string.

// syntax error
"abcabcabc"defdefdef"
^         ^
start    end