How do i create a large array in c++?

Apologies if this has been answered already but after searching didn't find what i was looking for.

i want to create an integer array of size 1500000 i.e int array[1500000] but my compiler wont allow it. I remember seeing something about using "new" but can't remember where i saw it. As you can tell am just beginning and trying to learn online(difficult).

If anyone could point me in the right direction or suggest a link to something it would be much appreciated.

6 Years
Discussion Span
Last Post by frogboy77

You are not able to create a large array because there isn't enough memory in stack memory. So you have to allocate it and use heap memory like so :

int size = 10e10;
int array = new int[size];

//..utilize array

delete [] array; //release memory for later use

But usually, you might want to do something like this :

std::vector<int> array(10e10,0); //create an array of size 10e10, initialize to 0

to firstperson
tried your first suggestion and got two compile errors

invalid conversion from int* to int
type int argument given to delete, expected pointer

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.