C ++ will be a function of two-dimensional arrays as parameters

A two-dimensional array will be passed as a parameter to the function, this parameter should be the function prototype is defined as (the number of columns of a two-dimensional array of type int. 4):

int (*a)[4];    //true
int a[][4];     //true
int *a[4];      //false

Appreciated that the above code: The [] in conjunction with the foregoing type, the first line defines a first pointer to a, it points to an array of four int elements, while in other blog where we said, [] may be substantially * equivalent and therefore represents the second method are possible. The third row represents the meaning is completely different, it defines a 4 comprises an array of type int *, i.e., each array element is a pointer to a pointer of type int.

Since the definition of function prototypes, we said in the definition of an array of pointers, the number of columns has a two-dimensional array passed to the function, so we only need a few lines as a parameter passed to another function, the function can accept array any number of rows, but only when accepted definition specifies the number of columns of the array.

Here const be used with caution, because there already is an indirect relationship, the error, and details about const pointer prone to see another blog.

Released three original articles · won praise 0 · Views 322

Guess you like

Origin blog.csdn.net/Nemoosi/article/details/104219612