37.0k views
3 votes
When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list.

User Alcalyn
by
4.4k points

1 Answer

4 votes

Answer:

size of all dimensions but the first.

Step-by-step explanation:

This is because of a certain thing known as addressing. Compiler, in order to access any data, needs to know its address in memory.

If we don't pass in the value for any dimension after the first, compiler can't calculate the address of given array location we may want to access inside a function.

E.g.

void Foo(int bar[][3]) {

bar[1][2];

}

In the above example, the compiler needs to know the no. of columns in "bar" array to figure out the address of bar[1][2] and access the data underneath.

Because, in order to go to 2nd row in the array, compiler needs to know how much memory allocation (columns) is in a row.

User Mamafoku
by
4.0k points