The following program crashes when I try to print the value of v. I’m trying to understand why. Any suggestions?
#include <stdio.h>
int main() {
int v[5000000];
printf("\n\nv = %p", v);
return 0;
}
EDIT: the program does not segfault if instead of allocating 5000000 elements I allocate 500000 or less.
EDIT(2): increasing the stack size solved the problem. On Linux, I increase the stack size after reading the answer of stephane-rouberol (using ulimit -s <some_large_number>).
Congrats, you have stack overflow 🙂
Find a way to increase the size of the stack or just allocate the array dynamically: