Today, I saw this post in the group discussion post of Gmail:
[Learn-Linux-c- CPP] converting a one-dimensional array to a pointer to an array inbox x zhangzhe benzhemin@gmail.com 11 - 10 - 28 Send to learning - Linux:Code: # Include <Stdio. h> Int Main ( Void ){ Int A [ 10 ] = { 1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 }; Int (* P )[ 2 ] = ( Int (*)[ 2 ]) A; printf ( " % D \ n " ,** P); printf ( " % D \ n " , ** (P + 1 ); Printf ( " % D \ n " ,* A ); Return 0 ;} A is just a pointer, why is it converted to int ( *)[ 2 ] Is it converted to a two-dimensional pointer? In fact, the following code can also be compiled and run. # Include <Stdio. h> Int Main ( Void ){ Int A [ 10 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 }; Int (* P )[ 2 ] = ( Int (*)[ 2 ]) & A; printf ( " % D \ n " ,** P); printf ( " % D \ n " , ** (P + 1 ); Printf ( " % D \ n " ,* A ); Return 0 ;} Hard Int (* P )[ 2 ] = ( Int (*)[ 2 ]) A; and Int (* P )[ 2 ] = ( Int (*)[ 2 ]) And a; are the two conversions equivalent.
Here we can clearly see that this netizen is confused with the concept, as described below.
A is just a pointer. Why is it converted to int (*)[2] Is it converted to a two-dimensional pointer?
We know that in C language, the array name is a constant, that is, the const volume. After the above changes, A is not converted to a pointer type such as int (*) [2, it is still maintained
The original property, except that p is a pointer type such as int (*) [2] and is forcibly directed to the address. This means that if the pointer P is used for access,
The 10 integers are interpreted as two-dimensional arrays.
There is also the following description:
HardInt(* P )[2] = (Int(*)[2]) A; andInt(* P )[2] = (Int(*)[2]) And a; are the two conversions equivalent.
The two descriptions above are consistent, because during parsing: the essence of a and & A is the same, and they all point to a fixed area in the memory; therefore, the two conversions are equivalent.
I don't want to talk about it here. Welcome the heroes in the garden to discuss this issue.
The above is my personal point of view. If there is any improper situation, please make a picture .........................