程序清单3.1 limits.cpp
#include <iostream>
#include <climits> //头文件climits中包含了关于整型限制的信息。
int main()
{
using namespace std;
int n_int = INT_MAX; //INT_MAX为int的最大取值。
short n_short = SHRT_MAX; //SHRT_MAX为short的最大取值。
long n_long = LONG_MAX; //Long_MAX为long的最大取值。
cout << "int is " << sizeof(int) << " bytes." << endl; /*sizeof返回类型或变量的长度,单位为字节。
* (操作符是内置的语言元素,对一个或多个数据进行运算,并生成一个值。)*/
cout << "short is " << sizeof(n_short) << " bytes." << endl;
cout << "long is " << sizeof(long) << " bytes." << endl << endl;
cout << "Maximum values:" << endl;
cout << "int: " << n_int << endl;
cout << "short: " << n_short << endl;
cout << "long: " << n_long << endl << endl;
cout << "Minimum int value = " << INT_MIN << endl;
cout << "Bits per byte = " << CHAR_BIT << endl; //CHAR_BIT为字节的位数。
return 0;
}