C/C++教程

C++中各种类型的最大值和最小值

本文主要是介绍C++中各种类型的最大值和最小值,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
//Author:PanDaoxi
#include <iostream>
#include <climits>
using namespace std;
int main(){
	cout<<"最大值:"<<endl; 
	cout<<"int类型:"<<INT_MAX<<endl;
	cout<<"char类型:"<<CHAR_MAX<<endl;
	cout<<"short类型:"<<SHRT_MAX<<endl;
	cout<<"long类型:"<<LONG_MAX<<endl;
	cout<<"long long类型:"<<LLONG_MAX<<endl;
	cout<<"signed char类型:"<<SCHAR_MAX<<endl;
	cout<<"unsigned char类型:"<<UCHAR_MAX<<endl;
	cout<<"unsigned short类型:"<<USHRT_MAX<<endl;
	cout<<"unsigned int类型:"<<UINT_MAX<<endl;
	cout<<"unsigned long类型:"<<ULONG_MAX<<endl;
	cout<<"unsigned long long类型:"<<ULLONG_MAX<<endl; 
	cout<<endl<<endl<<"最小值:"<<endl;
	cout<<"char类型:"<<CHAR_MIN<<endl;
	cout<<"short类型:"<<SHRT_MIN<<endl;
	cout<<"int类型:"<<INT_MIN<<endl;
	cout<<"long类型:"<<LONG_MIN<<endl;
	cout<<"long long类型:"<<LLONG_MIN<<endl;
	cout<<"unsigned char类型:"<<SCHAR_MIN<<endl; 
	return 0;
} 
最大值:
int类型:2147483647
char类型:127
short类型:32767
long类型:2147483647
long long类型:9223372036854775807
signed char类型:127
unsigned char类型:255
unsigned short类型:65535
unsigned int类型:4294967295
unsigned long类型:4294967295
unsigned long long类型:18446744073709551615


最小值:
char类型:-128
short类型:-32768
int类型:-2147483648
long类型:-2147483648
long long类型:-9223372036854775808
unsigned char类型:-128

--------------------------------
Process exited after 0.533 seconds with return value 0
请按任意键继续. . .
这篇关于C++中各种类型的最大值和最小值的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!