int、unsigned int溢出

关于int类型,unsigned int类型的溢出,测试代码如下:

#include 
using namespace std;
int main(){
	unsigned int max32=0xffffffff;
	cout<<"unsigned_int_max="<<max32<<endl;
	max32++;
	cout<<"unsigned_int_max+1="<<max32<<endl;

	int int_max=0x7fffffff;
	cout<<"int_max="<<int_max<<endl;
	cout<<"int_max+1="<<++int_max<<endl;

	int int_min=-2147483648;
	cout<<"int_min="<<int_min<<endl;
	cout<<"int_min-1="<<--int_min<<endl;

	while(1);
}

输出
int、unsigned int溢出_第1张图片

你可能感兴趣的:(C++)