|
|
|
|
|
|
|
for (col = minCol; col < colLength; col++)
for (row = minRow; row < rowLength; row++)
.
.
. // Whatever processing is required |
|
|
|
|
|
|
|
|
Passing Two-Dimensional Arrays as Parameters |
|
|
|
|
|
|
|
|
In Chapter 11, we said that when one-dimensional arrays are declared as formal parameters in a function, the size of the array usually is omitted: |
|
|
|
|
|
|
|
|
void SomeFunc( /* inout */ float list[],
/* in */ int size )
{
.
.
.
} |
|
|
|
|
|
|
|
|
If you include a size in the square brackets, the compiler ignores it. As you learned, the base address of the actual parameter (the memory address of the first array element) is passed to the function. The function works for an actual parameter of any size. Because the function cannot know the size of the caller's actual array, we either pass the size as a parameteras in SomeFunc aboveor use a declared constant if the function always operates on an array of a certain size. |
|
|
|
|
|
|
|
|
When a two-dimensional array is passed as a parameter, again the base address of the actual array is sent to the function. But you cannot leave off the sizes of both of the array dimensions. You can omit the size of the first dimension (the number of rows) but not the second (the number of columns). Here is the reason. |
|
|
|
|
|
|
|
|
In the computer's memory, C++ stores two-dimensional arrays in row order. Thinking of memory as one long line of memory cells, the first row of the array is followed by the second row, which is followed by the third, and so on (see Figure 13-7). To locate table[1][0] in this figure, a function that receives table's base address must be able to know that there are four elements in each rowthat is, that the table consists of four columns. Therefore, the declaration of a formal parameter must always state the number of columns: |
|
|
|
|
|