C language learning notes (6): How to differentiate pointer arrays and array pointers from the surface of variable declarations, language learning pointers
Example:
Int * p [5] is a pointer Array
Int (* p) [5] is an array pointer
To distinguish the two, you only need to look at the modifier around variable name p.
Here we need to clarify two points:
1. No matter whether int * p [5] Or int (* p) [5], it should not be regarded as a whole, but as some modifiers to modify the Variable p, so that p can be accurately defined;
2. The priority of [] is higher than that of *, and the modifier of the same priority is used. The compilation method is from left to right.
* P [5] Because [] has a high priority, [] modifies the variable name p first, so p is an array name, and then looks at other modifiers, it can be found that it is an int * type array, that is, p is a pointer array.
(* P) [5] Since () and [] have the same priority, so compile from left to right, then * modify p first, so p is a pointer variable, then, let's look at other modifiers. We can see that p is an int array pointer.
There are still a lot of considerations for modifying variables during declaration, such:
Const int p and int const p are the same thing. They both represent an int type constant.
Const int * p can be seen from left to right as: int type constant pointer, const modifies int type, then * p indicates p is a pointer, so p is a pointer to a constant, and the value of p itself is variable.
Const int * const p Remove two const and you can see that it declares an int pointer, and then there are two modifiers, one used to limit the int (that is, the type pointed by the pointer ), A Variable p itself, so p is a pointer with immutable values, and the value to which it points must also be immutable.
Const int const * const p is still an int pointer, and the second const modifier * obviously has no meaning, so the above statements are actually completely consistent.