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?
-
3What's the language you are talking about? – Yu Hao Jun 23 '16 at 04:34
-
1Possible duplicate of [Why do we need to specify the column size when passing a 2D array as a parameter?](http://stackoverflow.com/questions/12813494/why-do-we-need-to-specify-the-column-size-when-passing-a-2d-array-as-a-parameter) – melpomene Jun 23 '16 at 04:40
-
I am talking about c , – nathan Jun 23 '16 at 05:43
-
Yeah, I saw that post before . But that lost me ..... – nathan Jun 23 '16 at 05:44
1 Answers
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.

- 46
- 8
-
Hi,Rajeev. Thanks for you good post and reference. That really gave something new to me. However, I am still unclear with one sentence:"Since the called function does not allocate space for the array, it does not need to know the overall size, so the number of rows, NROWS, can be omitted. The width of the array is still important" – nathan Jun 24 '16 at 15:24
-
Just remember a 2d array is implicitly array of pointers, and as you know for every array size must be mentioned, and here the size is column size .@user3529352 – Rajeev Ranjan Jun 25 '16 at 12:27