and I was doing a program, that isn’t so important. Apparently, I cant send parameters to a float function.
the code look something like this
float myfunction(float array[1][2])
{
// ...
return 0;
}
int main()
{
float array[1][2];
int foo = 0;
// assigning values to the array
foo = myfunction(array[1][2]);
return 0;
}
when I try to compile, I get the error “cannot convert parameter 1 from ‘float’ to ‘float [][2]”
What is wrong? And how can I solve it?
A couple of things.
First, a function prototyped
float myfunction(float array[1][2])is confusing (you), since what it actually mean is:float myfunction(float array[][2])orfloat myfunction(float (*array)[2]). The function accepts a pointer to (one or more) array(s) of two floats.Second, the error you get is because the function accepts a pointer to an array, while you’re tryinmg to pass it single float – element [1][2] of the two-dimensional array
float array[1][2]. Perhaps you meant to pass the entire array to the function?