关于给unsigned int 给负值的计算问题
#include <iostream>
int main(void)
{
using namespace std;
int a = 1;
unsigned int b = -1;
cout << (a + b) << endl;
cout << b << endl;
system("pause");
return 0;
}
--------------------------------------------------------------
#include <iostream>
int main(void)
{
using namespace std;
int a = 1;
unsigned int b = -2;
cout << (a + b) << endl;
cout << b << endl;
system("pause");
return 0;
}
其中第一个结果是:
0
4294967295
第二个结果是
4294967295
4294967294
我们都知道int的范围是:-2147483648~~2147483647
unsigned int的范围是:0~4294967295
那为什么第一个的输出的结果不是:
4294967296
4294967295
请高手解答一下,迷惑中!