3.1
#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 n_long << "bytes." << endl;
cout << "long long is " << sizeof n_llong << "bytes." << endl;
cout << endl;
cout << "Maximum values: " << endl;
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 << endl;
system("pause");
return 0;
}
本文通过一个简单的C++程序展示了不同整数类型(int, short, long, long long)的字节大小及最大值,并输出了int类型的最小值与每字节位数。
248

被折叠的 条评论
为什么被折叠?



