In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains how the wild pointer of c language is produced. Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how the wild pointer of c language is produced.
1, the pointer variable is not initialized, any pointer variable will not automatically become a NULL pointer when it is created, its default value is random.
Therefore, the pointer variable should be initialized at the same time as it is created, either setting the pointer to NULL or letting it point to legitimate memory.
# include void Swap (int * p1minint * p2) {int * tmp; * tmp=*p1; * p1 invalid address. The program warns that the value of the uninitialized local variable tmp,*tmp cannot be accessed because tmp is not initialized and its address is a random value (0xcccccccc)}.
If it is not initialized, the compiler will report an error 'point' may be uninitializedin the function.
2. After the pointer is released, it is not set empty.
Pointers do not assign NULL after free or delete, they just free the memory that the pointer refers to, but do not deal with the pointer itself. At this point, the pointer points to the unknown (random, incorrect, and undefined).
After the pointer is released, the pointer should be set to NULL immediately to prevent the generation of wild pointers.
Int main () {char* p; p = (char*) malloc (10); printf ("% s\ n", p); if (paired null) {free (p);} free (p); / / when releasing p again, because it has been released once before, it will report an error return 0;} so far, I believe you have a better understanding of "how the c language wild pointer is generated". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.