Single quotes vs. double quotes in C or C++

前端 未结 13 1452
别那么骄傲
别那么骄傲 2020-11-21 07:14

When should I use single quotes and double quotes in C or C++ programming?

13条回答
  •  庸人自扰
    2020-11-21 08:05

    Double quotes are for string literals, e.g.:

    char str[] = "Hello world";
    

    Single quotes are for single character literals, e.g.:

    char c = 'x';
    

    EDIT As David stated in another answer, the type of a character literal is int.

提交回复
热议问题