Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - The concept of pointer in C language
The concept of pointer in C language
Let me talk about my understanding.

int * p; ? //When defining (or declaring) a pointer variable, the * in front of the variable P is only used to indicate that the variable P is a pointer variable rather than an integer variable. Int refers to a memory address of type int, and a pointer is essentially an address. Any type of pointer variable occupies 4 bytes of memory space (that is, 32-bit binary number). Since the address values stored in pointer variables are all 32 bits, why use them? This is to facilitate the operation of pointer variables. For example,

int? * pn? //Define a pointer variable to an integer.

Charles? * str? //Define a pointer variable to a character type.

//Assume that the initial values of pn and str are 0x 1000.

pn++; ? //pn is increased by 1, and the value of pn is 0x 1004, because the int type occupies 4 bytes and points to the next memory header address of the int type.

str++; ? //str is increased by 1, and the value of str is 0x 100 1, because the char type accounts for 1 byte, pointing to the first memory address of the next char type. From the above example, we can know that the pointer variable is preceded by the type in order to point to the memory space of the type variable, so the pointer of this type can be passed.

The significance of the type of int* is that the variable p is the name of the pointer variable, not the whole of *p, * only plays an explanatory role when defining the pointer variable, and int* is not a whole. You should remember that saying that P is an int* pointer is a simplified form for convenience, and the * here only serves as a marker explanation. Every poINTer variable of type int is preceded by an *.

int *p,* q; ? //Two pointer variables pointing to integer variables are defined.

int *p,q; ? //p is a pointer variable and q is an ordinary variable.

I hope it can help you understand.