Distinguish zero-valued pointers, NULL pointers, and wild pointers

Zero-valued pointer : It is a pointer with a value of 0, which does not store any memory address. It can be any pointer type, it can be a generic variant type void or it can be char , int*, etc.

Null pointer : NULL is a standard macro definition used to represent a null pointer constant. In fact, the null pointer is just a programming concept, just like a container may have two basic states: empty and non-empty, and when it is not empty, it may be inside A value stored is 0, so a null pointer is an artificially thought pointer that does not provide any address information.
In C++, we think that the 0 pointer is a null pointer

wild pointer
: a pointer to garbage memory, unlike a null pointer, a wild pointer cannot be avoided by simply judging whether it is NULL, but can only be minimized by developing good programming habits. Operating on wild pointers can easily lead to program errors.
Situations where wild pointers may occur: 
(1) The pointer variable is not initialized, any pointer variable will not automatically become a NULL pointer when it is just created, and its default value is random;
(2) The pointer is not set to a value after delete or free Empty, people mistakenly believe that the pointer is legal
(3) The pointer operation goes beyond the scope of the variable. Do not return pointers or references to stack memory, as stack memory is freed when the function ends

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325842144&siteId=291194637