无效的主要(){如果(的sizeof(int)的-1个)的printf(QUOT;真&QUOT);其他的printf(QUOT;假"); ; [英] void main() { if(sizeof(int) > -1) printf("true"); else printf("false"); ;

查看:128
本文介绍了无效的主要(){如果(的sizeof(int)的-1个)的printf(QUOT;真&QUOT);其他的printf(QUOT;假"); ;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void main()
{
    if(sizeof(int) > -1)
        printf("true");
    else
        printf("false");    
}

我所期望的输出是真实的,但它是假的。任何人都可以请解释我要输出的原因。

I expected the output to be true but it is false. Can anybody please explain me the reason for the output.

推荐答案

的sizeof(INT)的类型为为size_t ,它是一个无符号整型。所以在EX pression 如果(sizeof的(INT)-1个) 1 转换一个无符号整数,这是非常大的。

sizeof(int) is of type size_t, which is an unsigned integer type. So in the expression if(sizeof(int) > -1), -1 is converted to an unsigned integer, which is very big.

BTW,使用 INT主而不是非标准无效的主要

BTW, use int main instead of the non-standard void main.

这篇关于无效的主要(){如果(的sizeof(int)的-1个)的printf(QUOT;真&QUOT);其他的printf(QUOT;假"); ;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆