Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
99 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 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...