c++ - C++中 `long long int`的确切最大值是多少?

标签 c++ long-integer

我已经使用c++超过3个月了,我无法找出long long int中数字的确切最大值。

有人知道值(value)吗?

最佳答案

这取决于系统。 C++标准仅保证long long int will be 64-bits的最小大小。到目前为止,这也是最常见的大小。

如果使用64位大小,则可以表示的最大数量为2^63 - 1,等于9223372036854775807。之所以如此精确,是因为我们需要一半的组合位用于负数,然后一个用于0,其余的用于正数。

特定系统上的最大值还可以通过以下方式通过程序检查:

#include <iostream>
#include <limits>

int main() {
    std::cout << std::numeric_limits<long long int>::max();
}

Output:

9223372036854775807

关于c++ - C++中 `long long int`的确切最大值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58710120/

相关文章:

python - 为什么 int(maxint) 给出的是 long,而 int(int(maxint)) 给出的是 int?这是 NumPy 错误吗?

c++ - 在C++中获取当前时间跨平台

c++ - Qt.pro 文件 : adding path which includes "include" directory doesn't work

java - 如何在java中运行时比较两个长值

java - Scanner.hasNextLong 错误

c - 尝试打印一个无符号长整数,但得到一个不同的数字

c++ - QSharedPointer::isNull() 和 operator!() 之间的区别

c++ - 为什么我的 map 分配会导致编译器错误?

python - Cython/Python/C++ - 继承 : Passing Derived Class as Argument to Function expecting base class

java - 将 long 转换为 int 得到 0