为什么长长和长长的最大值产生相同的输出
Why do the max values of long and long long produce the same output?
#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;
}
输出:长和长的变量正在产生完全相同的最大值,我不确定为什么。长度值应该输出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
long
不能保证长32位;它仅必须是至少 32位。您的实现将long
定义为具有64位。请注意,即使long
和long long
在您的实现上具有相同的范围,但它们还是不同的类型。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 输出没有重复元素的动态数组(收缩数组)C++
- 为什么长长和长长的最大值产生相同的输出