开发者

c programming query regarding sizeof operator Please specifythe output with reason in windows and linux [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_开发问答 Closed 12 years ago.
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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜