本文介绍了如何获得动态分配二维阵列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经动态分配的二维数组。这里是code

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。

then it will print 4.

推荐答案

您无法找到 arrofptr 的大小,因为它只是一个指针的指针。您定义使用数组的数组。有没有办法,只有一个指针告诉大小的信息,你需要保持的尺寸的信息吧。

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.

这篇关于如何获得动态分配二维阵列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 01:30