将指针的二维数组传递给函数 C [英] Passing 2D array of pointer to function C

查看:24
本文介绍了将指针的二维数组传递给函数 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个二维指针数组

main.c

Int32 * pRxSeqAddr[2][2];

func(pRxSeqAddr);

/

func.c

void func( Int32** pRxSeqAddrPtr)
{

///
}

我收到此错误:

argument of type "Int32 *(*)[2]" is incompatible with parameter of type "Int32 **

我知道如果它是一维指针数组,那么这个函数调用很好,但二维却让我烦恼..

I know if it was 1D array of pointer then this function call is fine, but 2D is nagging me..

请帮忙

推荐答案

将 func.c 更改为:

Change func.c to:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆