在C语言中:
char a = 'a';
sizeof(char) = 1;
sizeof(a) = 1;
sizeof('a') = 4;
在C++语言中:
char a = 'a';
sizeof(char) = 1;
sizeof(a) = 1;
sizeof('a') = 1;
这是ISO C和ISO C++的一个区别:
In C, character literals(字符常量) such as 'a' have type int, and thus sizeof('a') is equal to sizeof(int).
In C++, character literals have type char, and thus sizeof('a') is equal to sizeof(char).