通过引用传递2D数组以起作用 [英] Pass 2D array to function by reference

查看:63
本文介绍了通过引用传递2D数组以起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在我的主要功能中,我正在创建2D数组:

So in my main function I'm creating a 2D array:

int dataDim = 100;
float inData[2][dataDim];

我想将其传递给一个函数,以便在其中填充数据.如何以一种我可以直接填写的方式传递它?也许

I want to pass it to a function where I will be able to fill it up with data. How to pass it in a manner that I will be able to fill it up directly? Maybe

function(float** array)

然后访问array[0][0]可能不起作用?奇怪的是我找不到关于此的任何快速示例.

and then accessing array[0][0] probably doesn't work? Strange how I can't find any quick example about this.

推荐答案

在C语言中,必须知道多维数组的大小是这样传递的,尽管您可以根据需要省略某些大小.

in C, multidimensional arrays' sizes must be known to pass as such, although some sizes may be omitted, if you like.

完全

void function(float array[][100]); 
void function(float (*array)[100]);

在语法上有效

尽管编译器可以合法地忽略大小2.

Although the compiler may legally ignore the size 2.

void function(float array[2][100]);

这篇关于通过引用传递2D数组以起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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