C++ 中 int 类型最大值获取方法
在 C++ 中,整数类型 int 的最大值可以通过使用标准库中的 limits 头文件来获取。具体代码如下:
#include <iostream>
#include <limits>
int main() {
std::cout << "最大值: " << std::numeric_limits<int>::max() << std::endl;
return 0;
}
输出结果将会是:
最大值: 2147483647
这是因为 C++ 中的 int 类型通常是 32 位的,所以最大值是 2^31 - 1。
原文地址: https://www.cveoy.top/t/topic/mXBg 著作权归作者所有。请勿转载和采集!