首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

sizeof 有关问题

2012-02-13 
sizeof 问题sizeof( N )sizeof( NULL )sizeof( \n )为什么返回值都是4呢?[解决办法]K & R说:A character c

sizeof 问题
sizeof( 'N ')
sizeof( 'NULL ')
sizeof( '\n ')
为什么返回值都是4呢?

[解决办法]
K & R说:
A character constant is a sequence of one or more characters enclosed in single quotes as in 'x '. The value of a character constant with only one character is the numeric value of the character in the machine 's character set at execution time. The value of a multi-character constant is implementation-defined.
注意两点:
1、在C语言中(C++是不同的),字符常量(character constant)是字符的机器表示的数值,也就是说,是一个整数(int型),所以sizeof的结果是整数的大小。
2、一个字符常量的引号内有多个字符,结果是“implementation-defined”(由实现定义的)。

热点排行