Segmentation fault and malloc

I have a very simple c code main.c as below

#include <stddef.h>

int main(int argc,char **argv)

int N=1<<20;

float *x;
x=(float )malloc(Nsizeof(float));
if (x == NULL )
printf(“Memory allocation error”);

for(int i=0;i<N;i++){

return 0;


And I compile it with
$ pgcc -mcmodel=medium -o aout main.c

I get sementation fault error if I set N=1<<20 while N=1<<10 works fine. It looks like unless I declared a array xarr[N] and point the pointer to there, I get seg fault for N=1<<20. Can someone help? Thanks._

Try changing stddef.h to stdlib.h. Not sure if malloc should be defined in stddef.h.

Thank you!!! It works!