sizeof('z') result unexpected [duplicate]
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')
issizeof(int)
精彩评论