In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what is "wild pointer" and "suspended pointer" in C language. In daily operation, I believe many people have doubts about what "wild pointer" and "suspended pointer" are in C language. The editor has consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubts about "wild pointer" and "suspended pointer" in C language. Next, please follow the editor to study!
Wild pointer (wild pointer)
"wild pointer": a pointer that has not been initialized, so it is uncertain that the pointer points specifically. For example, the following sample code:
Void * p; / / at this time p is the "wild pointer"
Because the wild pointer may point to any memory segment, it may corrupt normal data or cause other unknown errors. In the actual C language program development, when defining pointers, we should generally try to avoid the emergence of "wild pointers", which can be solved by assigning initial values:
Void * p = NULL;void * data = malloc (size)
"hanging pointer" (dangling pointer)
"dangling pointer" (dangling pointer): a pointer to which the memory the pointer originally points to has been freed. The popular point is understandable: the pointer points to a piece of memory, and if the memory is later reclaimed (freed) by the operating system, but the pointer still points to the memory, then the pointer is a "dangling pointer". For example, the following sample code:
Void * p = malloc (size); assert (p); free (p); / / now p is "dangling pointer"
The "dangling pointer" in C language can cause unpredictable errors, and once such errors occur, it is difficult to locate. This is because after free (p), the p pointer still points to the previously allocated memory, and if the memory is temporarily accessible by the program without causing conflicts, then using p later will not cause an error.
Therefore, in the actual C language program development, in order to avoid unpredictable errors caused by "dangling pointers", pointer p is often assigned to NULL after releasing memory:
Void * p = malloc (size); assert (p); free (p); / / avoid "dangling pointers" p = NULL;. This is the end of the study on "what are wild pointers and dangling pointers in C language". I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.