Declaring 2d arrays globally and locally

Hello. In this example
1
2
3
4
5
int main()
{
    int A[3000][3000];
    return 0;
}


the program doesn't work, and as far as I understand it's because A is too large.

but

1
2
3
4
5
6
int A[3000][3000];

int main()
{
    return 0;
}


Here I declare A as global array, yes? In this case, everything works just fine, no errors, program returns 0.
Why is this happening? And if I want to use arrays with large dimensions,is declaring array globally acceptable?
Thank you.
Last edited on
Actually the first one runs just fine. What error do you have?
It says "program.exe" has stopped working after I compile, and it returns big negative number
Quite strange... I just tried and nothing unusual happens.
Local variables are stored on the stack which is typically smaller than the space available for global variables. Your array takes 36,000,000 bytes for 32-bit integers and twice that for 64 bit integers.

You can probably set the stack size in your compiler options.
Topic archived. No new replies allowed.