Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

X,Y passing size for the array in C function

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)?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...