现在的位置: 首页 > 综合 > 正文

-1L与1U的比较

2013年09月10日 ⁄ 综合 ⁄ 共 902字 ⁄ 字号 评论关闭

-1L的类型是long int,1U的类型是unsigned int。当进行比较时,会有一个隐式的类型转换。在C中,当一个变量是long int 时,如果long int 的取值范围能覆盖unsigned int 的时候,unsigned int 的变量被转换成long int ;如果long int 的取值范围不能覆盖unsigned int 时,两个变量同时被转换成unsigned long。

在这里,假设int是16位的,而long int 是32位的,这时,long int 的取值范围能覆盖unsigned int ,所以1U被转换成lont int,这时有:-1L<1U。

现在的机器里,int 和long 一般都是32位的,这时,long int 的取值范围就不能覆盖unsigned int 的了,这种情况下,两个变量都被转换成为unsigned long。转换后,-1L的值是 0xffffffff,这时比较的结果就是:-1L>1U。

 

转载自:http://blog.csdn.net/heziling/article/details/329499

-1L的类型是long int,1U的类型是unsigned int。当进行比较时,会有一个隐式的类型转换。在C中,当一个变量是long int 时,如果long int 的取值范围能覆盖unsigned int 的时候,unsigned int 的变量被转换成long int ;如果long int 的取值范围不能覆盖unsigned int 时,两个变量同时被转换成unsigned long。

在这里,假设int是16位的,而long int 是32位的,这时,long int 的取值范围能覆盖unsigned int ,所以1U被转换成lont int,这时有:-1L<1U。

现在的机器里,int 和long 一般都是32位的,这时,long int 的取值范围就不能覆盖unsigned int 的了,这种情况下,两个变量都被转换成为unsigned long。转换后,-1L的值是 0xffffffff,这时比较的结果就是:-1L>1U。

 

转载自:http://blog.csdn.net/heziling/article/details/329499

抱歉!评论已关闭.