Comment


Two-D Arrays as Function Parameters

With old C compilers, if a function took a 2D array as a parameter, the function definition was required to explicitly show the number of columns (but not rows) in the array. The number of rows of the array could be a parameter.

void function ( int x[][15], int nrows )
{
    . . .
}

Modern C compilers that conform to the current ANSI Standard allow both the number of rows and number of columns in array parameters to be variables. The following is legal for modern compilers:

void print2DArray ( int nrows, int ncols, int x[nrows][ncols] )
{
    . . .
}

In the above, the number of rows and number of columns must appear first (before the array) so that they are defined before they are used. This will work for the most recent Bloodshed Dev-C++ and for gcc.



Next Page         Previous Page Home