有符号数和无符号数运算的时候,有符号数会自动向无符号数转换

无符号整型与有符号整型相运算规则
 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
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2022-01-14
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案