< previous page page_721 next page >

Page 721
0721-01.gif
Figure 13-7
Memory Layout for a 2-Row by 4-Column Array
void AnotherFunc( /* inout */ int arr[][4] )
{
    .
    .
    .
}
Furthermore, the number of columns declared for the formal parameter must be exactly the same as the number of columns in the caller's actual array. As you can tell from Figure 13-7, if there is any discrepancy in the number of columns, the function will access the wrong array element in memory.
Our AnotherFunc function works for a two-dimensional array of any number of rows, as long as it has exactly four columns. In practice, we seldom write programs that use arrays with a varying number of rows but the same number of columns. To avoid problems with mismatches in formal and actual parameter sizes, it's practical to use a Typedef statement to define a two-dimensional array type and then declare both the actual and the formal parameters to be of that type. For example, we might make the declarations

 
< previous page page_721 next page >