传递指针二维数组函数C [英] Passing 2D array of pointer to function C
本文介绍了传递指针二维数组函数C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有指针的二维数组
main.c
Int32 * pRxSeqAddr[2][2];
func(pRxSeqAddr);
/
func.c
void func( Int32** pRxSeqAddrPtr)
{
///
}
我得到这个错误:
I get this error:
argument of type "Int32 *(*)[2]" is incompatible with parameter of type "Int32 **
我知道,如果它是指针的一维数组那么这个函数调用是好的,但2D唠叨我。
I know if it was 1D array of pointer then this function call is fine, but 2D is nagging me..
请帮忙
推荐答案
更改func.c为:
void func(Int32 *pRxSeqAddrPtr[][2])
{
}
在一般情况下,以二维数组传递给函数,你需要指定数组大小为所有,但第一个维度,所以在这个例子中,你所需要的[2]在过去的维度,但你可以选择忽略它的第一维,即
In general, to pass 2D arrays to functions you need to specify the array dimensions for all but the first dimension, so in this example you need the [2] for the last dimension but you can optionally omit it for the first dimension, i.e.
void func(Int32 *pRxSeqAddrPtr[2][2])
{
}
也将是有效的,但有些多余。
would also be valid, but somewhat redundant.
这篇关于传递指针二维数组函数C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文