在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).

posted on 2013-10-23 21:00  运动和行动  阅读(655)  评论(0编辑  收藏  举报