测试代码:
#include<cstdio> #include<iostream> using namespace std; int main() { unsigned int a = 3; int b=2,c=1; if(b<c-a) cout<<"int transform to unsigned int"<<endl; cout<<b<<" "<<c-a<<endl;; cout<<a*-1<<endl; long long d = 5; cout<<a-d<<" "<<sizeof(a-d)<<endl; return 0; }
运行结果:
int transform to unsigned int 2 4294967294 4294967293 -2 8
int和unsigned int的混合表达式,计算时会将int转换为unsigned int
普通情况下会将范围小的隐式转换为范围大的,但对于int和unsigned int,就说不准哪个范围大了,经测试是会将int转换为unsigned int(被坑过。。。)