Re: Some doubts on variable-length array




Ben Bacarisse wrote:
foo(2, 2, tab); /* A. don't understand */

This calls "lies" to foo telling it that the array is 2x2 so foo sees it
as if it were "int tab[2][2] = {{0, 1}, {2, 3}};". Element [1][1] is 3
and this is what is printed.

I know it before that functions regard an array argument same as a
pointer. So how can the layout/dimension of an actual array argument be
known inside the function body? Are new meanings/semantics given to
array arguments when they are variable-length array?

foo(3, 3, tab); /* A. don't understand */

This call does not "lie". So inside foo it is seen as it was defined and
element [1][1] is the number 4.

The original array is: /* int tab[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; */
, if it is used instead, then foo(3, 3, tab); lies again, right?

I can understand the original sample code in your way, but get more
anxious on how a function knows the layout/dimension of actual array
arguments.

.



Relevant Pages