Single, double quotes and sizeof('a') in C/C++

后端 未结 2 1767
难免孤独
难免孤独 2021-01-31 07:25

I was looking at the question Single quotes vs. double quotes in C or C++. I couldn\'t completely understand the explanation given so I wrote a program:

#include         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 07:51

    In C, character constants such as 'a' have type int, in C++ it's char.

    Regarding the last question, yes,

    char ch = 'a';
    

    causes an implicit conversion of the int to char.

提交回复
热议问题