Today, two-dimensional arrays are used as parameters to pass the program, through the Internet search, for their own problems to do a collation.
1, in the called function of the shape parameter group definition can omit the size of the first dimension, the second dimension cannot be omitted, as follows:
void fun (int a[5][20]); Legal
void fun (int a[][20]); Legal
void fun (int a[5][]); Not legal
void fun (int a[][]); Not legal
When a two-dimensional array as a formal parameter, the first dimension can be omitted, the second dimension cannot be omitted, this is the compiler principle is limited, in memory by the array rules are stored (in rows), but not the branch and column, if the parameter does not describe the number of columns, the system cannot determine how many rows should be.
2, the real parameter group dimension can be greater than the shape parameter group dimension, such as:
void fun (int a[5][20]);//formal parameter is a[5][20]
int a[10][20]; Defining Real parameter Groups
The parameter group is then only part of the data of the real parameter group.
3. String two-dimensional array assignment
3.1. Initialize the value of the assignment
void Fun (char a[][20]) {//implement function function} void Main () {char str[][20]={"123", "456", "789"}; Fun (str); }
3.2, use strcpy function, need #include<string.h>
void Fun (char a[][20]) {//implement function function} void Main () {char str[3][20]; strcpy (str[0], "123");//or with sprintf (str[0], "123"); strcpy (Str[1], "456");//or with sprintf (str[1], "456"); strcpy (str[2], "789");//or with sprintf (str[2], "789"); Fun (str); }
Assignment of a C-language two-dimensional array string