#include <iostream>
#include <climits>
int main()
{
using namespace std;
int n_int = INT_MAX;
short n_short = SHRT_MAX;
long n_long = LONG_MAX;
long long n_llong =LLONG_MAX;
cout << "int is " <<sizeof(int)<<" bytes."<<endl;
cout << "short is "<<sizeof n_short<<" bytes."<<endl;
cout << "long is "<<sizeof LONG_MAX<<" bytes."<<endl;
cout << "long long is "<<sizeof(n_llong)<<" bytes."<<endl;
cout << "Maximum values:"<<'\n';
cout << "int:"<<n_int<<endl;
cout << "short:"<<n_short<<endl;
cout << "long:"<<n_long<<endl;
cout << "long long:"<<n_llong<<endl;
cout << "Minimum int value = "<<INT_MIN<<endl;
cout << "Bits per byte = "<<CHAR_BIT;
}
可用类型名称或者变量名使用sizeof(),对类型名来说,必须有括号,而其他的例如变量名,括号不加强调。