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

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

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

13条回答
  •  Happy的楠姐
    2020-11-21 08:07

    I was poking around stuff like: int cc = 'cc'; It happens that it's basically a byte-wise copy to an integer. Hence the way to look at it is that 'cc' which is basically 2 c's are copied to lower 2 bytes of the integer cc. If you are looking for a trivia, then

    printf("%d %d", 'c', 'cc'); would give:
    

    99 25443

    that's because 25443 = 99 + 256*99

    So 'cc' is a multi-character constant and not a string.

    Cheers

提交回复
热议问题