#include<iostream>
#include<climits>
int main()
{
using namespace std;
int n_int = INT_MAX;
short n_shor = SHRT_MAX;
long n_long = LONG_MAX;
cout << "int is " << sizeof(int) << " bytes." << endl;
cout << "short is " << sizeof(short) << " bytes." << endl;
cout << "long is " << sizeof(long) << " bytes." << endl;
cout << "Maximum valuse:" << endl;
cout << "int:" << n_int << endl;
cout << "short:" << n_short << endl;
cout << "long:" << n_long << endl;
cout << "Minimum int value = " << INT_MIN << endl;
cout << "Bits per byte = " << CHAR_BIT << endl;
return 0;
}
通过climits库,调用其中的函数,得知编译环境下int、short、long的最大值,int最小值和每字节的bit数。同时得知,char是一字节的长度