In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
C language null type of pointer and null pointer and the role of wild pointer, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can get something.
Null type pointer-void*
Void is a null type, and void* is a null type pointer, also known as a universal pointer, that is, the pointer can receive any type of pointer and can point to any type of object, so the null type pointer cannot be dereferenced, and the type must be forced to convert to the corresponding pointer type before dereferencing operation can be carried out.
Null pointer type:
As a function parameter type, you can receive pointers of any type.
As the function return value type, outside the function, cast the type to the corresponding pointer type
You can compare the size with another void* type pointer
Note: null type pointers cannot be dereferenced; ±integer operations cannot be performed.
Null pointer-NULL
In C language, the null pointer NULL refers to the space with address 0.
# define NULL ((void*) 0)
We are not allowed to access this space, so we cannot dereference the NULL, so before dereferencing the pointer, we have to determine whether the pointer is null or not.
Wild pointer
A wild pointer is a pointer to an illegal or destroyed memory.
It is illegal to dereference a wild pointer.
The cause of wild pointer 1. The pointer did not initialize int main () {char* p; / / where p is the wild pointer return 0;}
Without initializing pointer p, p is a wild pointer. If you dereference p at this time and illegally access memory, the program will crash.
two。 The pointer crosses the boundary to access int main () {int arr [] = {1 return 2 int main 5}; int* p = arr; int i = 0; for (I = 0; I < 10; iTunes +) {printf ("% d", p [I]);} return 0;}
Although the above program runs normally, it is actually out of bounds; only the illegal memory space is accessed without changing the value of the space, and the program may not have time to report an error, but it does not mean that there is nothing wrong with the program, but for the following code, the program crashes:
Int main () {int arr [10] = {0}; int I = 0; int* p = arr; for (I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.