C++ signed和unsigned 大小比较
2016-10-27 10:02
501 查看
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:14px;">using namespace std;</span></span>
<span style="font-size:14px;"> int main() { unsigned int a = -1; int b = 0; if (a > b){ cout << "hello\n"; }else{ cout << "111111\n"; } cout << "test\n"; return 0; }</span></span>
如上图所示输出为 hello ;a与b比较的时候,a会自动转换成unsigned int类型进行比较。由于signed int的负数最高位是1,转换成unsigned int之后,就会变成一个很大的unsigned int型正数,所以a与b比较时a会大于b。所以会输出hello;
相关文章推荐
- signed 与 unsigned 比较大小的默认转换
- C++ 5(比较数的大小)
- Signed变量和Unsigned变量的比较
- signed和unsigned的比较
- C++ 习题 比较大小-类模板
- c++中比较三个数的大小
- c++中比较3个数值的大小
- linux c/c++ IP字符串转换成可比较大小的数字
- Why Not Mix Signed and Unsigned Values in C/C++?
- NO.3 C++中的signed和unsigned
- c++实现字符串strcmp()大小比较
- signed和unsigned的比较
- c++一个实现分数大小比较和各种运算的类
- c++关于signed和unsigned
- 我的c++学习(2)比较两个数字大小
- c++怎么比较5个字符串的大小并将其按从小到大输出
- signed和unsigned的比较
- C++模版函数: 按成员变量比较大小
- [C++]不用if比较两个数大小
- linux c/c++ IP字符串转换成可比较大小的数字