Big array gives segmentation error in C

前端 未结 4 2013
情话喂你
情话喂你 2020-12-04 02:48

I am really new to C, so I am sorry if this is a absolute beginner question, but I am getting a segmentation error when I am building large array, relevant bits of what I am

4条回答
  •  有刺的猬
    2020-12-04 03:45

    You are most likely getting a stack overflow, since you are creating a very large array on the stack. To avoid this, allocate the memory dynamically:

    unsigned long long *numbs = malloc(arr_size * sizeof(unsigned long long));
    

    Later, when you are finished with the array, free it again:

    free(numbs);
    

提交回复
热议问题