C language system learning 6 pointers preliminary

1. What is a pointer

In computers, a pointer is an object in a programming language whose value points directly to a value stored elsewhere in the computer's memory, using an address. Since the required variable unit can be found through the address, it can be said that the address points to the variable unit. Therefore, what visualizes the address is called a "pointer". It means that the memory unit with its address can be found through it.

In layman's terms
, a pointer is a variable that stores the address (number) of a memory unit.
2. Pointers and pointer
types There are various types of variables, including integers and floating-point types. The corresponding pointer will also have different types, and the type comes from the definition of the pointer

char *pc=null;
int *pi=null;
short *ps=null;
long *pl=null;
float *pf=null;
double *pd=null;

The type of the pointer determines how much authority (how many bytes can be manipulated) when dereferencing the pointer. For example: char* pointer dereference can only access one byte, while int* pointer dereference can access four bytes
3. Wild pointer

The wild pointer is that the position pointed by the pointer is unknown (random, incorrect, and not clearly limited). If the pointer variable is not initialized at the time of definition, its value is random, and the value of the pointer variable is the address of other variables. means that the pointer points to a variable whose address is ambiguous,

Reasons for the formation of wild pointers
1. The pointer is not initialized
2. The pointer is accessed out of bounds
3. The space pointed to by the pointer is released

How to avoid wild pointers
1. Pointer initialization
2. Be careful that the pointer is out of bounds
3. The space pointed to by the pointer is released and set to NULL in time
4. Check the validity of the pointer before using it

4. Pointer array
Pointer array is an array used to store pointers
such as int* arr[5]

Guess you like

Origin blog.csdn.net/qq_45742383/article/details/113744975