I. "&" and "*":
The "&" operation in a single object is the address of the operation object, and "*" is the content of the object pointed to by the pointer. The two are inverse operations for each other.
IntX,*P;
P= &X;
& (* P) = P indicates the pointer; * (& X) = X indicates the variable X.
II: Arithmetic operation of pointer:
The pointer operation is related to the base type. Generally, if p is a pointer and N is a positive integer, the actual address after the + (-) operation on the pointer P is:
P+(-) N*Sizeof(Base type)
Char * P;
Int * Q;
Float * TK;
// Assume that the current address is: P = 2110 H, q = 2231 H, TK = 2478 H
P + = 1 ; // P = p + 1 = 2111 H
Q + = 4 ; // Q = q + 4*4 = 2239 H
TK -= 3 ; // TK = TK-3*8 = 246ch
3. pointer auto-increment and auto-subtraction:
Pointer auto-addition and auto-subtraction are also address operations.
M= *P++Equivalent to m= *(P++)
The pointer P is used to assign the value of the variable currently referred to the variable M. P is used to add 1 to point to the next target variable.
M= * ++P is equivalent to M.= *(++P)
P adds 1 to point to the next target variable. Take the pointer P and assign the value of the variable currently referred to the variable M.
M=(*P)++And m= ++(*P)
The former is to assign the value of the variable referred to by the pointer P to the variable M, and then the variable * P automatically adds 1;
The latter assigns the value of * P, the variable referred to by P, to the variable M after adding 1.
4. subtraction between pointers:
Subtraction can be performed between pointers pointing to the same group of data types. The result of subtraction indicates the number of data records that are separated by two pointers.
V. relational operation of pointers:
P and q point to the same array. P> q indicates whether P points to the end of the position indicated by Q. If yes, the expression value isNon-0Otherwise, the value is 0.
6. subscript operation of the pointer:
P [I] = * (p + I );