When n is a big number, say 10^7
unsigned n, m;
scanf("%u %u", &n, &m);
long arr[n + 1];
// long *arr = malloc((n + 1) * sizeof(*arr));
for (size_t i = 1; i <= n; ++i)
arr[i] = 0;
I get segmentation fault when I declare arr as long arr[n + 1];
, but it works fine when I change to use malloc()
(with same number of space, as the marked code).
Why there's difference? I thought stack and heap share the same space, like the pic depicts.