如何获取动态分配的二维数组的大小 [英] How to get the size of dynamically allocated 2d array
本文介绍了如何获取动态分配的二维数组的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经动态分配了二维数组.这是代码
I have dynamically allocated 2D array. Here is the code
int **arrofptr ;
arrofptr = (int **)malloc(sizeof(int *) * 2);
arrofptr[0] = (int *)malloc(sizeof(int)*6144);
arrofptr[1] = (int *)malloc(sizeof(int)*4800);
现在我必须知道在 arrofptr,arrofptr[0],arrofptr[1] 中分配了多少字节?有没有办法知道尺寸?
Now i have to know that how many bytes are allocated in arrofptr,arrofptr[0],arrofptr[1]? is there any way to know the size?
如果我们要打印
sizeof(arrofptr);
sizeof(arrofptr[0]);
sizeof(arrofptr[1]);
然后它会打印 4.
推荐答案
你找不到arrofptr
的大小,因为它只是一个指向指针的指针.您正在使用它定义一个数组数组.没有办法只用一个指针来告诉size信息,需要自己维护size信息.
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.
这篇关于如何获取动态分配的二维数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文