In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what is the cause of wild pointer in c language". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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;} "what is the cause of c language wild pointer"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.