First, void f (a [] []); is incorrectly defined.
When two-dimensional data is used as a function parameter, you must specify the number of columns in the two-dimensional array so that the compiler can understand how to address it.
The correct method is void f (a [4] [6]).
Void f (a [] [6]); // The number of rows in a two-dimensional array can be omitted.
In addition, a two-dimensional array cannot be defined as its subscript with a very large number.
Void f (a [m] [N]); is a serious error;
Correct Application Mode 1
Void func1 (INT iarray [] [10])
{
}
Int main ()
{
Int array [10] [10];
Func1 (array );
}
Correct Application Mode 2 (using a one-dimensional pointer array as a parameter)
Void func2 (int
(* Parray) [10])
{
}
Void func2_1 (INT (* parray) []) // The code is compiled and cannot be called.
{
}
Int main ()
{
Int array [10] [10];
Func2 (array );
}
Correct Application Mode 3 (using two-dimensional array references as parameters)
Void func3 (INT (& parray) [10] [10]) // two dimensions must be specified here
{
}
Int main ()
{
Int array [10] [10];
Func3 (array );
}
Correct Application Mode 4 (using a two-dimensional pointer array as a parameter)
Void func4 (INT (* parray) [10] [10]) // you must specify two dimensions.
{
}
Int main ()
{
Int array [10] [10];
Func4 (& array );
}
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.
Supplement: When the double pointer is used as the form parameter, the passed real parameter must also be a double pointer, cleverly allocating memory space using new, which can be defined with a very large volume
Void func5 (INT ** parray, int M, int N)
{
}
# Include <ctime>
Int main ()
{
Int M = 10;
Int n = 10;
Int ** parray = new int * [m];
Parray [0] = new int [M * n];
// Allocate continuous memory and dynamically create two-dimensional arrays
// Parray [1] [0] cannot be used for addressing. You must specify the subscript addressing mode.
For (INT I = 1; I <m; I ++)
{
Parray [I] = parray [I-1] + N;
}
Func5 (parray, m, n );
}