简体   繁体   English

为什么这个 sizeof(int) 程序在运行时打印出 false ?

[英]why this sizeof(int) program prints out false on running?

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

This Programm While Running Prints Out "False".该程序在运行时打印出“False”。 Why Does This Happen?为什么会发生这种情况? Even though it's Size was 4?即使它的大小是4?

the result of sizeof() is unsigned value while the right side of the comparison is signed. sizeof() 的结果是无符号值,而比较的右侧是有符号的。 The compiler will convert the right side into unsigned (a very big number) first, then compare.编译器首先将右侧转换为无符号(一个非常大的数字),然后进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM