Maximum size of int array

I have written a simple program.
But I got a strange error:

1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
        int genotype[150000000]; 
    
}

RUN FAILED (exit value 1, total time: 131ms)

How can I save this amount of int?

(I have enough memory to save these amount of int and my computer is 64)
Your stack is too small. Put this on the heap, using new:

int* genotype = new int[150000000];
Hope that following will be useful ...

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

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:

1
2
3
#include <limits.h>
const int min_int = INT_MIN;
const int max_int = INT_MAX;

C++:

1
2
3
#include <limits>
const int min_int = std::numeric_limits<int>::min();
const int max_int = std::numeric_limits<int>::max();
Topic archived. No new replies allowed.