开发者

sizeof('z') result unexpected [duplicate]

开发者 https://www.devze.com 2023-03-08 19:44 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Size开发者_高级运维 of character ('a') in C/C++
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

精彩评论

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