Generally, when a two-dimensional array is passed to a function, the length of the second-dimensional array cannot be omitted.
Void fun (INT arr [] [6], int N)
In this case, the second dimension is fixed to death. But sometimes, we do need to process different two-dimensional arrays. Here is a clever method:
Considering that two-dimensional arrays are actually continuously stored, for example, arrays A [3] [4], then the elements followed by a [0] [3] are a [1] [0],
Based on this, you can use manual addressing to transmit an indefinite two-dimensional array to the function.
# Include <stdio. h> void fun (int * arr, int row, int col) {int I, j; for (I = 0; I <row; ++ I) {for (j = 0; j <Col; ++ J) printf ("% 4D", arr [I * Col + J]); printf ("\ n") ;}} int main () {int A [3] [4] ={{ 1, 2, 3, 4}, {5, 6, 7, 8 },{ 9, 10, 11, 12 }}; fun (int *) A, 3, 4); Return 0 ;}
Running result:
1 2 3 4
5 6 7 8
9 10 11 12