allocate matrix in C

前端 未结 7 1239
别跟我提以往
别跟我提以往 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:01

    what you can do is

    int (*mat)[col];
    mat=(int (*)[col])malloc(sizeof(*mat)*row);
    

    and then use this new matrix as mat[i][j]

提交回复
热议问题