Reputation: 844
Many people say compiler would not know the size information if no column size is provided. But How compiler knows the row size? And why column size can't be interpreted?
Upvotes: 2
Views: 1905
Reputation: 46
While passing an array as an argument to a function, compiler implicitly converts the array reference to the pointer. This can be clearly seen in the case of one dimensional array, like
int method(int *a)
int method(int a[])
Both these lines are equivalent here (although pointer and array reference are different) because whenever an array appears in an expression, the compiler implicitly generates a pointer to the array's first element, just as if the programmer had written &a[0]. However this rule is not recursive i.e. passing a 2d array is treated as pointer to an array, not a pointer to a pointer.
int method(int b[3][5]);
is converted to
int method(int (*b)[5]);
And since the called function doesn't allocate space for the array so size of row is not important, however size of column is still important to provide the size of array. For further reference you can visit here.
Upvotes: 2