有符号数和无符号数运算的时候,有符号数会自动向无符号数转换
1 #include<iostream> 2 #include<ctime> 3 #include <stdio.h> 4 #include<cstring> 5 #include<cstdlib> 6 #include <map> 7 #include <string> 8 using namespace std; 9 10 #if TEST 11 int main(){ 12 int a = -3; 13 unsigned int b = 2; 14 int c = a+b; 15 printf("c:%u\n", c); 16 printf("c:%d\n", c); 17 int x = -3; 18 unsigned int y = 2; 19 unsigned int z = x+y; 20 printf("z:%u\n", z); 21 printf("z:%d\n", z); 22 } 23 #endif
u c:4294967295
d c:-1
z:4294967295
z:-1
时间: 2024-11-15 19:38:08