It is highly recommended that huge variables be sent to the heap via malloc or new . But you can still have such a large array on the stack, increasing the size of the stack. This is often necessary when you can have extremely deep recursion.
Linux / gcc has a default size of 8 MB for the stack, while Windows has 1 MB. The stack size can be increased by adjusting the linker or binary settings.
[EDITED] For example, you can increase the size of the stack in gcc:
gcc -Wl,--stack,16777216 hello.c (This is only for MigW / cygwin gcc on Windows)
So, the stack will be 16 MB.
In addition, the stack size can be changed with the ulimit command, like (this is the easiest way on Linux):
ulimit -s 16777216
Note that ulimit -s will provide you with the current stack size.
Finally, you can call setrlimit in your program.
source share