Two-dimensional array names are used as real parameters or parameters, and two-dimensional arrays are used
1. method 1. void fun (int a [4] [6]); // specify the number of columns of a two-dimensional array when two-dimensional data is used as a function parameter.
Void fun (int a [] [6]) // The number of two-dimensional array rows can be omitted.
In addition, two-dimensional arrays cannot be defined as their subscripts using constants.
*/
Void fun1 (int a [] [3], int n) {// number of rows in the array
For (int I = 0; I <n; I ++ ){
For (int j = 0; j <3; j ++ ){
Printf ("% d", a [I] [j]);
}
}
}
/*
Method 2. void fun (int (* pArray) [6]) applies a one-dimensional pointer group as a parameter
*/
Void fun2 (int (* arr) [3], int n ){
For (int I = 0; I <n; I ++ ){
For (int j = 0; j <3; j ++ ){
Printf ("% d", arr [I] [j]);
}
}
}
/*
Method 3. void fun (int (& arr) [10] [10]) applies a two-dimensional array reference as a parameter. Two dimensions must be specified here.
Method 4. void fun (int (* arr) [10] [10]) uses a two-dimensional pointer array as a parameter. Two dimensions must be specified here.
Note: The above four methods are common, but when the array is passed, only the value is passed, and the input parameter is not changed.
Method 5. void fun (int ** arr, int m, int n) uses the double pointer as the shape parameter. The passed real parameter must also be a double pointer, cleverly allocating memory space using new, can be defined with a limit
Arr [I] [j] is wrong to get the value, because the compiler cannot properly address it, so we need to simulate the behavior of the compiler to convert the formula such as arr [I] [j]
Manually convert to * (int *) arr + n * I + j );