monk
monk

Reputation: 97

Passing a multidimensional array to a function

I want to pass a multidimensional array to a function. The problem is that the size of the array will only be known at runtime. I know the size of the "inner arrays". The unknown size is that of the "outer" array.

I have tried passing the array in my function prototype by specifying the unknown size as a variable of type int but this resulted in an error. My function prototype looked something like this:

float get_basket(float basket[number][5]);

number above is a global variable of type int.

Upvotes: 0

Views: 87

Answers (1)

Abhishek Bansal
Abhishek Bansal

Reputation: 12715

If the size of the array shall be known at run time then it is better to use vector or at least you should build the array dynamically through pointers.

As for the function argument, you can pass it as:

float get_basket(int basket[][5]);

or

float get_basket(int **basket);

Upvotes: 2

Related Questions