C language arrays and pointers
Const
There are some rules to note about pointers and Const. First, it is legal to initialize the address of the const data or non-const data to a pointer to a const or to assign a value to it.
However, you can only assign addresses of non-const data to normal pointers. (That is, a const value cannot be assigned to a normal pointer);
Pointers and multidimensional arrays:
Zippo = &zippo[0];
zippo+2 = = &zippo[2];
* (zippo+2) = = &zippo[2][0];
* (zippo+2) + 1 = = &zippo[2][1];
* (* (zippo+2) + 1) = = Zippo[2][1];
Pointer to multidimensional array:
Int (* PZ) [2]; >> PZ points to an array containing two int types;
( such as: zippo[4][2];)
INT * Pax[2]; >> Pax is an array of two pointer elements, each of which points to an int pointer;
( just like the meaning of the array, it declares two pointers, one is pax[0] and the other is pax[1])
(such as pax [0] = Zippo; pax[1] = ZIPPP; >> *pax[0] = = *pax[1];)
An array variable is a const pointer, so it cannot be assigned a value:
int a[] <==> int * Const A = ....
The array variable itself expresses the address, so:
int a[10]; int * p = A; No need to take & address
But the cell expression of an array is a variable, it needs to use & address
A = = &a[0]
The [] operator can do the array, or it can do the pointer:
P[0] <==> a[0];
* the operator can do the pointer, or it can do the array:
*a = 25;
C Language > Pointers