为什么的sizeof(INT)不大于-1? [英] Why sizeof(int) is not greater than -1?

查看:234
本文介绍了为什么的sizeof(INT)不大于-1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的C code:
为什么是输出假?????

为什么4> -1 ???

code:

 的#include<&stdio.h中GT;诠释主(){
    如果(的sizeof(int)的-1个)
        的printf(真);
    其他
        的printf(假);
    返回0;
}


解决方案

由于的sizeof(int)的无符号。所以-1转换为一个大的无符号值。

this is my C code : why is the output "False " ?????

why 4 > -1???

code :

#include <stdio.h>

int main() {
    if (sizeof(int) > -1)
        printf("True");
    else
        printf("False");
    return 0;
}

解决方案

Because sizeof(int) is unsigned. So -1 is converted to a large unsigned value.

这篇关于为什么的sizeof(INT)不大于-1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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