C语言:指向数组的指针及容易混淆的概念
When learning C language, the pointer part did not learn very solid
Several unusual pointers:
Int (* P) [4] pointer to an array, pointing to an array like int a[4]
Int (* P) points to the function, which returns the int value
The int * P pointer to the pointer points to a pointer to the int variable
=============================== contrast
Int (* P) [4]
Int * P [4], where the latter is an array of pointers containing
4 int * type elements
Int (* P)()
Int * P (), where the latter is a function that returns the data of the int * type
Int (* P) [4]
Int * * P this issue needs to be discussed in detail We know that array index operations, such as a[3], are actually * (a+3), but * (a+3)
Such an operation does not simply take the address (constant or variable) plus 3 to fetch the value of the memory cell,
It's a+ 3*sizeof??? Then the memory unit value)? It can be called sizeof???"Step"〃?
Thus, each pointer variable must have a basic data type when it is declared, for example:
Declare basic step
Int * P int int
Int * * P int * pointer
Int (*p) [4] int a[4] 4 * int
The int (*p) () func compiler determines that
Int * PT[4], this is an array containing 4 int * P
Int * FN (), which is the function, returns 1 int * P
In fact, the int * P pointer level is equivalent to int * PT[4],
but the PT here is
Pointer constants, while P is pointer variables, can be p二PT, that is, the first address of the PT[4] array is assigned to pointer P?
P is used to store the address of pointer variables in memory and can be used to index this set of int variables, so say
It is the pointer to the pointer, and the first step is the length of the "pointer" type?
〃P[X][Y]" means..:
First read the value of the pointer variable from the P + X* sizeof ("pointer") p[X],
Then read the value of the int type variable from the p[X] + Y* sizeof (int) p[X][Y]?
In contrast, int (* Pa) [4] is called the pointer to an array, and here it is
A pointer to a one-dimensional array, assuming the assig