c++下无穷的使用

 

#include <iostream>
#include <climits>
using namespace std;

int main()
{
	cout<<"INT_MAX: "<<INT_MAX<<endl;
	
	cout<<"INT_MIN: "<<INT_MIN<<endl;
	
	//最轻微的上溢是 INT_MAX+1,结果是INT_MIN
	cout<<"INT_MAX+1: "<<INT_MAX + 1<<endl;
	
	//最严重的上溢是 INT_MAX+INT_MAX,结果是 -2
	cout<<"INT_MAX+INT_MAX: "<<INT_MAX + INT_MAX<<endl;
	
	//最轻微的下溢是 INT_MIN - 1,结果是 INT_MAX
	cout<<"INT_MIN-1: "<<INT_MIN - 1<<endl;
	
	//最严重的下溢是 INT_MIN +INT_MIN,结果是 0
	cout<<"INT_MIN+INT_MIN: "<<INT_MIN + INT_MIN<<endl;
	return 0;
}
/*
INT_MAX:----------------------(2147483647)
INT_MIN:----------------------(-2147483648)
INT_MAX+1:--------------------(-2147483648)
INT_MAX+INT_MAX:--------------(-2)
INT_MIN-1:--------------------(2147483647)
INT_MIN+INT_MIN:--------------(0)
*/