I am now studying C as it’s required for some of my university subjects…
We have studied 1-d arrays in class, but, I’ve decided to save myself some work and move forward, so I’m already studying matrices (bidimensional arrays).
I want to pass an array to a function and compute the average value of each row. If this was to be done with a single array, the function prototype could be:
void computesAvg(int v, int students);
where students actually coincides with the maximum number of elements of v.
My issue is that, when I try to extend this idea, for something like:
void computeAvg(int v, int classes, int students);
After compiling a program with the above function prototype, I get an error, saying that the type is incomplete or not specified…
However, something like:
#define CLASS 7 #define STUD 10 void computeAvg(int v[CLASS][STUD], int classes, int students);
already works… My only issue is that the prototype the teacher specified was the one without any dimensions…
I know arrays are actually changed when passed to procedures/functions, so maybe it has something to do with it and the compiler needs to know the dimensions beforehand?