Skip to main content
Logo image

Section 24.4 Passing Multidimensional Arrays to Functions

In order to pass a two-dimensional array to a function we need to let the computer know the number of columns in the array so that array addressing can be performed correctly.
Remember, a two-dimensional array is stored row by row, so as long as we know how many elements are stored in each row (that is, the number of columns), we (and also the computer) can find the start of the second row, the start of the third row, etc. The computer can therefore find the element at location [i][j] by going to row i and then counting off to element j of that row.
As you can see in the below code window, if a function is to receive a 2-dimensional array as a parameter then the function definition needs to include the number of columns of the array (but it does not need to be told the number of rows.) Just having this information the computer can perform array addressing correctly.

admin.....open in new window