at-*_*ard 0 c++ c++builder visual-c++ c++11 c++14
#include <iostream>
using namespace std;
#include <climits>
int main () {
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 << "llong: " << n_llong << endl << endl;
//cout << endl;
cout << "Minimum int value = " << INT_MIN << endl;
cout << "Maximum int value = " << INT_MAX << endl;
cout << "Bits per byte = " << CHAR_BIT << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出: 长和长的长变量产生完全相同的最大值,我不知道为什么.long值应该输出最大值2147483647.
int is 4 bytes.
short is 2 bytes.
long is 8 bytes.
long long is 8 bytes.
Maximum values:
int: 2147483647
short: 32767
long: 9223372036854775807
llong: 9223372036854775807
Minimum int value = -2147483648
Maximum int value = 2147483647
Bits per byte = 8
Run Code Online (Sandbox Code Playgroud)
long不保证是32位长; 它只需要至少 32位长.您的实现已定义long为64位.请注意,即使long和long long对您的实现相同的范围内,但它们是截然不同的类型.
| 归档时间: |
|
| 查看次数: |
1246 次 |
| 最近记录: |