int数组的最大尺寸? [英] Maximum size of int array?
问题描述
我写了一个简单的程序。
I have written a simple program.
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int genotype[150000000];
}
但我得到一个奇怪的错误:
But I get a strange error:
运行失败(退出值1,总时间:131ms)
RUN FAILED (exit value 1, total time: 131ms)
我保存这个金额 int
?
(我有足够的内存来保存 int
s和我的计算机是64位)
(I have enough memory to save this amount of int
s and my computer is 64-bit)
推荐答案
将这个放在堆上,使用new:
Your stack is too small. Put this on the heap, using new:
int* genotype = new int[150000000];
我希望以下内容有用。
已签署的字元:-127至127(请注意,不是-128至127;这里包含1的补充平台)
unsigned char:0 to 255 cybo
plain char:-127到127或0到255(取决于默认的char signedness)
signed short:-32767到32767
unsigned short:0到65535
signed int:-32767 to 32767
unsigned int:0 to 65535
signed long:-2147483647 to 2147483647
unsigned long:0 to 4294967295
signed long long:-9223372036854775807至9223372036854775807
unsigned long long:0 to 18446744073709551615
signed char: -127 to 127 (note, not -128 to 127; this accommodates 1's-complement platforms)
unsigned char: 0 to 255
"plain" char: -127 to 127 or 0 to 255 (depends on default char signedness)
signed short: -32767 to 32767
unsigned short: 0 to 65535
signed int: -32767 to 32767
unsigned int: 0 to 65535
signed long: -2147483647 to 2147483647
unsigned long: 0 to 4294967295
signed long long: -9223372036854775807 to 9223372036854775807
unsigned long long: 0 to 18446744073709551615
或者你可以使用limit.h来了解你的程序所依赖的。
例如,这将是如何找到int的最大范围:
Or you can use limit.h to find out around what your program relies on. For example, this is how you will find maximum range for int:
C:
#include <limits.h>
const int min_int = INT_MIN;
const int max_int = INT_MAX;
C ++
#include <limits>
const int min_int = std::numeric_limits<int>::min();
const int max_int = std::numeric_limits<int>::max();
这篇关于int数组的最大尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!