Calloc a Two-Dimensional Array

前端 未结 4 1463
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-11 10:32

To make a two dimensional array, I\'m currently using the following:

int * own;

own = (int *)calloc(mem_size, sizeof(int));

for (i=0;i

        
4条回答
  •  我在风中等你
    2021-02-11 11:25

    Use:

    int ** own; // int**, not int*
    own = calloc(mem_size, sizeof(int*)); //int*, not int
                                          // And remove the explicit cast.
    

提交回复
热议问题