0

When I declare table[1005][1005] inside a function and run the program it is stopped.

enter image description here

When I declare it globally it work. But what's the reason?

#include<stdio.h>
#include<string.h>

int table[1005][1005];

int main()
{
    printf("Hello there");
    return 0;
}
  • 4
    The stack is a limited resource usually the default is 1MB on windows and 8 or so on linux. Your array size is likely `4 * 1005 * 1005` but could be `8 * 1005 * 1005` depending on the `sizeof(int)` – drescherjm Feb 04 '20 at 14:37
  • When you declare it globally it's not on the stack. [https://stackoverflow.com/questions/44359953/are-global-variables-in-c-stored-on-the-stack-heap-or-neither-of-them](https://stackoverflow.com/questions/44359953/are-global-variables-in-c-stored-on-the-stack-heap-or-neither-of-them) – drescherjm Feb 04 '20 at 14:49
  • You could declare the array locally, but prefix with `static`. The prefix `static` will put the array into another memory region that usually has more capacity than the stack. – Thomas Matthews Feb 04 '20 at 15:11

0 Answers0