简体   繁体   English

指向多维数组的指针多维数组

[英]Pointer multidimensional array to multidimensional array

In C++, is there a way to convert a float** to a float[][] type? 在C ++中,是否可以将float**转换为float[][]类型? I also would like to know how to convert it the other way around too. 我也想知道如何将其转换为其他方式。

You don't need to convert anything. 您无需进行任何转换。 Just dereference it by [][] : 只需通过[][]取消引用即可:

float **a;

// allocate memory //

a[0][0] = 1;

Be careful to don't touch out-of-bound items which didn't allocate. 注意不要触摸未分配的越界项目。

you can look here to see some more examples, but basically as MM said, you don't need to convert and you can always do: 您可以在此处查看更多示例,但基本上就像MM所说的那样,您无需进行转换,可以随时这样做:

int x[10];
int *y = x;

same with 2 dimensional arrays 与二维数组相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM