What is the wild pointer and null pointer of C language?
This article mainly introduces "what are wild pointers and null pointers of C language". In daily operation, I believe that many people have doubts about what wild pointers and null pointers of C language are. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what are wild pointers and null pointers of C language". Next, please follow the editor to study!
One: wild pointer
Concept: the memory address that the wild pointer points to is unknown (random, incorrect, and unrestricted).
Description: pointer variables are also variables, which can be assigned at will. However, it doesn't make sense to assign any numeric value to a pointer variable, because such a pointer becomes a wild pointer, and the area the pointer points to is unknown (the operating system does not allow you to manipulate the area of memory that the pointer points to).
Note: the wild pointer will not cause an error directly, but the memory area pointed to by the wild pointer will cause a problem.
Code example:
Int a = 100 leading int * ptrac p = a; / / assigning the value of a to the pointer variable pMagee p is wild pointer, ok, it will not be a problem, but there is no meaning p = 0x12345678; / / assigning a value to pointer variable p, p is wild pointer, ok, there will be no problem, but it is meaningless * p = 1000; / / it is not possible to assign a pair of wild pointers
Assigning the value of a to the pointer variable pMagep is a wild pointer, ok, which is not a problem, but it doesn't make sense.
Assign a value to the pointer variable p, p is a wild pointer, ok, it won't be a problem, but it doesn't make sense.
1.1: the cause of the wild pointer
1. Pointer uninitialized: the pointer variable does not automatically become a NULL pointer when it is created, its default value is random, and the space it refers to is random.
Code example:
Int main () {int * p; * p = 20; return 0;}
(personal understanding: pointer variables are randomly assigned by the operating system, do not point to a specific space, do not have a foothold)
two。 Pointer out-of-bounds access: the pointer points beyond a reasonable range, or returns a pointer or reference to stack memory when a function is called, because the function is released at the end of the stack.
Code example:
Int main () {int arr [10] = {0}; int * p = arr; for (int I = 0; I