比如下面这个
程序代码:
输出结果是 a is small
先把b 转成unsigned int
再比较,得出的a 小的结论
可是为什么要把b先转成unsigned int?
下面的帖子有解释,可是没怎么看懂尤其是
Binary operations between different integral types are performed
within a "common" type defined by so called usual arithmetic conversions
(see the language specification, 6.3.1.8).
In your case the "common" type is unsigned int.
查了一下language specification, 6.3.1.8,
http://www.
参考了一下,是不是
两个需要比较的数值,如果一个数值转换成另一种类型,
并且能很好的被表示出来,那这个数值就不被转换
所以1000 被转成int的话也可以被毫无压力的表示出来,所以1000不被转换,
所以b=-1则被转换为unsigned int?再进行比较?
程序代码: int main(void) {
unsigned int a = 1000;
int b = -1;
if(a > b)
printf("a is big¥n");
else
printf("a is small¥n");
return 0;
}输出结果是 a is small
先把b 转成unsigned int
再比较,得出的a 小的结论
可是为什么要把b先转成unsigned int?
下面的帖子有解释,可是没怎么看懂尤其是
Binary operations between different integral types are performed
within a "common" type defined by so called usual arithmetic conversions
(see the language specification, 6.3.1.8).
In your case the "common" type is unsigned int.
查了一下language specification, 6.3.1.8,
http://www.
参考了一下,是不是
两个需要比较的数值,如果一个数值转换成另一种类型,
并且能很好的被表示出来,那这个数值就不被转换
所以1000 被转成int的话也可以被毫无压力的表示出来,所以1000不被转换,
所以b=-1则被转换为unsigned int?再进行比较?

The quieter you become, the more you can hear







