You can use a two-dimensional array masterpiece as an argument or a parameter, you can specify the size of all dimensions when defining the parameter group in the called function, or you can omit the size description of the first dimension, such as:
void Func (int array[3][10]);
void Func (int array[][10]);
Both are legal and equivalent, but cannot omit the size of the second or higher dimension, as the following definition is illegal:
void Func (int array[][]);
Because arguments are passed from the beginning address of the array, stored in memory by array rules (stored in rows), not branches and columns, if the number of columns is not specified in the formal parameter, the system cannot determine how many rows should be, and cannot specify only one dimension without specifying a second dimension, the following is wrong:
void Func (int array[3][]); The real parameter group dimension can be greater than the shape parameter group, for example, the real parameter group is defined as:
void Func (int array[3][10]);
The shape parameter group is defined as:
int array[5][10];
The shape parameter group only takes part of the real parameter group, and the remainder does not work.
As you can see, when you use a two-dimensional array as an argument, you must indicate all dimensions or omit the first dimension, but you cannot omit the size of the second or higher dimension, which is limited by the compiler principle. When you're learning how to compile this lesson, you know that the compiler handles arrays like this:
for array int p[m][n];
If you want to take the value of P[i][j] (i>=0 && i<m && 0<=j && J < N), the compiler is addressing this, and its address is:
P + i*n + j;
As can be seen from the above, if we omit the size of the second dimension or higher, the compiler will not know how to properly address it. But when we write the program, we need to use a two-dimensional array of various dimensions are not fixed as a parameter, this is difficult, the compiler does not recognize Ah, how to do? Do not worry, although the compiler is not recognized, but we can not think of it as a two-dimensional array, but instead of it as a normal pointer, and then add two parameters to indicate the number of dimensions, and then we have to manually address the two-dimensional array, so that the two-dimensional array as a function of the parameter transfer, according to this idea, We can change the parameter of the dimension fixed to the parameter of the dimension, for example:
void Func (int array[3][10]);
void Func (int array[][10]);
Into:
void Func (int **array, int m, int n);
How C language passes two-dimensional arrays as arguments to functions