Differences between single-quotes and double-quotes in C

前端 未结 5 431
梦如初夏
梦如初夏 2021-01-29 16:39

Recentely I have seen that if I use printf with \'foo\' I get a warning.

printf(\'numero\');

warning: character con

5条回答
  •  别那么骄傲
    2021-01-29 16:50

    '' is used to denote characters while "" is used to denote strings.

    printf expects a const char*(a string) as its first argument. You need to use "" for that. If you use '', the compiler will complain and will tell you that printf expects a const char* as its first argument and not a char.

    FYI, adding more than one character into '' (like 'numero') will make a multi-character literal whose value is implementation defined.

提交回复
热议问题