Dimensional and two-dimensional array of function pointers as arguments

Whether at work or questions on recent brush LeetCode. Mistakenly believe that a two-dimensional and two-dimensional array of pointers as function parameters are equivalent. This perception is wrong. The reason, or understanding of arrays and pointers are not in-depth. Today my understanding to make a summary:

If a parameter is a two-dimensional function pointer, but you passed argument it is a two-dimensional array. Then you will compile error.

Why am I wrong to think that a two-dimensional array of parameters as a function of time equivalent to two-dimensional pointer it?

I think the reason why I think so: the one-dimensional array as a function of time parameter, the compiler will array name as a pointer to the first element of the array pointer. So I take it for granted that: Since the one-dimensional and one-dimensional array pointer equivalent in function arguments, it should be a two-dimensional array is equivalent to two-dimensional pointer ah.

But unfortunately, two-dimensional array as a function parameter and is equivalent to two-dimensional pointer. Because the array as a function of conversion parameter pointer is not transitive . That means you can not think of one-dimensional and one-dimensional array pointer as a function parameter equivalent, considered two-dimensional and two-dimensional arrays of pointers is equivalent. Without such transmissibility in the C language.

In fact, think about it, it is very easy to understand. Two-dimensional array is actually an array of arrays (that is, it is a one-dimensional array, and each element but it is a one-dimensional array). When the two-dimensional array as a function of the parameters, such as int a [3] [4]; its first dimensional array will be converted into a pointer, is the equivalent of passing a pointer to an array of pointers. I.e., as a function of parameters, int a [3] [4] and int (* p) [4] equivalents. That int (* p) [4] and int ** pp equivalent to it? It is certainly not equivalent, p is a pointer to type int [4], and is directed pp type int *.

Guess you like

Origin www.cnblogs.com/LydiammZuo/p/12149901.html