How to get the size of dynamically allocated 2d array

前端 未结 4 1794
余生分开走
余生分开走 2021-01-17 06:07

I have dynamically allocated 2D array. Here is the code

int **arrofptr ;
arrofptr = (int **)malloc(sizeof(int *) * 2);
arrofptr[0] = (int *)malloc(sizeof(int         


        
4条回答
  •  不知归路
    2021-01-17 06:14

    You can't find size of arrofptr, because it is only a pointer to pointer. You are defining an array of arrays using that. There's no way to tell the size information with only a pointer, you need to maintain the size information yourself.

提交回复
热议问题