allocate matrix in C

前端 未结 7 1218
别跟我提以往
别跟我提以往 2020-11-29 03:49

i want to allocate a matrix.

is this the only option:

int** mat = (int**)malloc(rows * sizeof(int*))

for (int index=0;index

        
相关标签:
7条回答
  • 2020-11-29 04:26

    You may also use calloc, which will additionally zero initialize the matrix for you. The signature is slightly different:

    int *mat = (int *)calloc(rows * cols, sizeof(int));
    
    0 讨论(0)
提交回复
热议问题