Xiao Bai's basic summary of C language pointers, and Xiao Bai's C language pointers
Pointer
A pointer is the address pointing to a piece of memory space, a pointer variable is a variable, and a variable storing the first address of a piece of memory space. We generally refer to pointers as pointer variables.
Pointer definition and assignment:
Type Description * variable name column such as int * p;
Difference int * p = NULL and * p = NULL
Int * p = NULL; // defines the pointer Variable p, and sets the value of p to 0x00000000 at the same time, instead of setting the value of * p to 0x0000000, this process is called initialization int * p; * p = NULL; // defines the pointer Variable p, Set * p to NILL, that is, assign NULL to the memory pointed to by p, however, the memory referred to by p may be invalid, and the compilation may display a memory access error. Then, make the following changes to give it a valid memory. Int I = 10; int * p = & I; * p = NULL; // The value in I is changed from 10 to 0, and the p value is not changed, that is, the memory address is not changed.
Pointer size
Int * P; sizeof (p); // the pointer size is determined by the number of digits of the computer. The 32-bit Host size is 4 bytes, And the 64-bit Host size is 8 bytes.
Pointer operation
It should be noted that the pointer type, plus 1 is the size of a pointer type.
Int a [10]; int * p = & a; // + 1, with the sizeof (int) * 1 byte added instead of sizeof (int [10]) * 1 byte
Usage type of pointer
Pointer format
Array form
Int a [10]; int * P = a; p [0] = 1; // pointer array form * (p + 1) = 2; // pointer form
The compilation process of modifying content through pointers
1. Find the address of the pointer variable
2. Find the content address through the address of the pointer variable
3. Find the content through the address
4. modify content