X,Y在C函数中传递数组的大小 [英] X,Y passing size for the array in C function

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

问题描述

我声明了我的函数,我想从对角线[0] [0] ... [5] [5]和[0] [5] ... [5] [0]中找到最小值。
我有算法,但是我的问题是实际的函数头。

我在为函数创建正式参数时遇到了问题。
我知道我们必须至少传递 x [] [this] 数组的大小,但我尝试了各种组合,甚至是

  double minimum(int size,double x [] [size]){...} 

double minimum( double x [] [int size]){...}

调用:

  minimum(10,x [] [10])
error:']'令牌之前的预期表达式`

第二种情况在函数声明中给出错误:

 错误:在'int'之前的期望表达式



<有人可以告诉问题是什么(或问题)?

解决方案

double minimum(int rowsize,int size,double x [rowsize] [size]){...}
或简单的


$ b

因此,指定<$ c $> double double(int rowsize,int size,double x [] [size]){...} code> rowsize 是opt不过在这里,我想它是方形的 size x size ,所以它会是

$ b


$ b

double minimum(int size,double x [] [size]){...}



所以你是正确的。



如何调用它?



minimum(10,x)


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.

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]){...} or simply

double minimum(int rowsize,int size, double x[][size]){...}

So specifying rowsize is optional.

But here I guess it is square size x size so it will be

double minimum(int size, double x[][size]){...}

So you are correct in that.

How to call it?

minimum(10,x)

这篇关于X,Y在C函数中传递数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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