开发者

sizeof('z') result unexpected [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Size开发者_高级运维 of character ('a') in C/C++

Why does this program output 4 and not 1?

void main()
{
   printf("%d",int(sizeof('z')));
}

'z' is a character and sizeof('z') must print 1?


'z' is a character literal and in C a character literal is of type int. So sizeof('z') equals sizeof(int) on your implementation.


Sizeof char.

Perhaps surprisingly, character constants in C are of type int, so sizeof('a') is sizeof(int)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜