I have heard many people saying that when we want to pass a 1D array to a function fun the following prototypes are equivalent:
1.
int fun(int a[]);
int fun(int a[10]);
int fun(int *a);
I have even heard people say that the 1st and 2nd one are internally converted to the 3rd one in C. I guess that this is true because doing something as sizeof(a) in the definition of the function declared in 2 gives the size of a pointer in bytes (and not 10*sizeof(int)).
Now that being said, I have seen texts claiming that to pass a 2D array to a function the following are equivalent:
1.
int fun(int a[][10]);
int fun(int (*a)[10]);
And here again I have heard people say that in C the 1st one is internally converted to the second one. If that is true, the following should have been equivalent right?
1.
int fun(int a[][]);
int fun(int (*a)[]);
But unfortunately the first one puts forth a compilation error but the second one does not:
1 | int fun(int a[][]);
| ^
t.c:2:13: note: declaration of ‘a’ as multidimensional array must have bounds for all dimensions except the first
This makes me feel that C is treating a in the first as a multidimensional array each of whose element is an integer array but their type is not complete (int[] namely).
While in the second one, a is just a pointer to an array of integers (with size not specified or incomplete type). And the two are indeed different and one format is not equivalent to the other...
Can anyone guide me in details as to what actually happens in C, in each of these cases?