Where the array is stored when I use new

When we need an array, we can either:

int a[10];

or

int *a = new int[10];
delete [] a; // after you finish


So what is the difference between them? As I know if I use approach 1, the array is stored in stack while in approach 2, the array is stored in heap, ocrrect?

Thanks in advance.




You are correct.
That is indeed correct.


The difference is, as far as my understanding goes:

When using the stack, the variable is stored inside the program itself, an address, or offset, is declared for that variable.

When using the heap, a pointer is stored and that pointer is set when the operating system sections off a portion of memory outside the program.
Thanks.
Topic archived. No new replies allowed.