The multi-dimensional array as a function parameter is described in C and pointer:
The multi-dimensional array names used as function parameters are passed in the same way as the one-dimensional array names-actually passing a pointer to the first element of the array. However, the difference between the two is that each element of a multi-dimensional array itself is another array, and the compiler needs to know its dimension to evaluate the subscript expression of a function parameter.
In this article, there is no objection to the general int-type two-dimensional array, but the situation for the string array seems a bit different. The following is an example:
# Include <unistd. h> # include <stdio. h> int main (void) {char * choise [] = {"test choise 1", "this is test choise 2", null}; print (choise );} int print (char ** PS) {char ** pp = Ps; while (* PP) {printf ("% s \ n", * PP ); PP ++ ;}}
If this program follows the rules described above, when executing the print function pp ++, the program should not run normally. The result is that the program can print the string correctly.
For a string array, It is a character-shaped two-dimensional array, but it also has its own particularity, that is, the string is an array of characters ending with '\ 0. That is to say, each sub-array of the Two-dimensional array choise ends with '\ 0'. In this way, we can tell the compiler parameter PS dimension. The form parameter of the print function is equivalent to Char (* PS) [22].
In this program, there is also a small problem, that is, the difference between null and. Null is nothing, that is, 0. "" Is an empty string, and the empty string is also a string. It only has one character '\ 0 '.