I have set stack size to 2000Kb by ulimit -s 2000 and ulimit -Ss 2000 for hard limit. And in the below program i have allocated appox 2040000(510000 x 4) bytes which is less than i limited i.e,. 2048000(2000*4)bytes but i see that my program crashes! Can anybody suggest why this happens.
#include <stdio.h>
#include <malloc.h>
int main()
{
int a[510000] = {0};
a[510000] = 1;
printf("%d", a[510000]);
fflush(stdout);
sleep(70);
}
EDIT 1: Crash is not because of the array index out of bound as i tried lower index and still crashes. This happens only when i limit by ulimit.