c - Proc crashes even if it allocates less memory than limited by ulimit -
i have set stack size 2000kb ulimit -s 2000 , ulimit -ss 2000 hard limit. , in below program have allocated appox 2040000(510000 x 4) bytes less limited i.e,. 2048000(2000*4)bytes see program crashes! can suggest why 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 not because of array index out of bound tried lower index , still crashes. happens when limit ulimit.
int a[510000] array index 0 509999. a[510000] outside array range.
Comments
Post a Comment