c programming query regarding sizeof operator Please specifythe output with reason in windows and linux [closed]
void main()
{
char c='0';
printf("%d %d",sizeof(c),sizeof('0'));
}
In C, size of char literal
is equal to sizeof(int)
. So sizeof('0')
gives the value of sizeof(int)
on your implementation.
Also sizeof(char)
is always 1 as mandated by the Standard.
The output will be 1 4
. The type of the '0'
literal is int
, which on most systems has a size of 4
. The C standard requires that sizeof(char)
is 1
.
If you get anything less than 4
, get in your time machine, and dial in +25 years
.
精彩评论