X,Y 在 C 函数中传递数组的大小 [英] X,Y passing size for the array in C function
问题描述
我已经声明了我的函数,我想从对角线 [0][0] ... [5][5] 和 [0][5] ... [5][0] 中找到最小值.我有算法,但我的问题是实际的函数头.
I've declared my function where I want to find the minimum from diagonals [0][0] ... [5][5] and [0][5]... [5][0]. I have the algorithm but my problem is with the actual function header.
我在为函数创建形式参数时遇到问题.我知道我们必须至少将数组的x[][this]
大小传递给函数,但我尝试了各种组合,甚至
I have problem with creating the formal arguments for the function.
I know that we have to pass at least x[][this]
size of array to the function, but I tried various combinations, even
double minimum(int size, double x[][size]){...}
double minimum(double x[][int size]){...}
第一种情况调用时报错:
The first case gives an error when calling:
minimum(10, x[][10])
error: expected expression before ']' token `
第二种情况在函数声明中报错:
The second case gives an error in declaration of function:
error: expected expression before 'int'
有人能说出问题是什么(或问题是什么)?
Can someone tell what the problem is (or problems are)?
推荐答案
double minimum(int rowsize,int size, double x[rowsize][size]){...}
或者干脆
double minimum(int rowsize,int size, double x[][size]){...}
所以指定 rowsize
是可选的.
So specifying rowsize
is optional.
但这里我猜它是方形的size x size
所以它会是
But here I guess it is square size x size
so it will be
double minimum(int size, double x[][size]){...}
所以你是对的.
最小值(10,x)
这篇关于X,Y 在 C 函数中传递数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!