Tag: 整数提升

当二元运算符两侧的符号性不同时,促销规则如何工作?

考虑以下程序: // http://ideone.com/4I0dT #include <limits> #include <iostream> int main() { int max = std::numeric_limits<int>::max(); unsigned int one = 1; unsigned int result = max + one; std::cout << result; } 和 // http://ideone.com/UBuFZ #include <limits> #include <iostream> int main() { unsigned int us = 42; int neg = -43; int result = us + neg; […]

types转换 – 无符号到signed int / char

我试着执行下面的程序: #include <stdio.h> int main() { signed char a = -5; unsigned char b = -5; int c = -5; unsigned int d = -5; if (a == b) printf("\r\n char is SAME!!!"); else printf("\r\n char is DIFF!!!"); if (c == d) printf("\r\n int is SAME!!!"); else printf("\r\n int is DIFF!!!"); return 0; } 对于这个程序,我得到的输出: […]