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

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

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

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 08:09

    Use single quote with single char as:

    char ch = 'a';
    

    here 'a' is a char constant and is equal to the ASCII value of char a.

    Use double quote with strings as:

    char str[] = "foo";
    

    here "foo" is a string literal.

    Its okay to use "a" but its not okay to use 'foo'

提交回复
热议问题