In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what the wild pointer is in the C language. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
(1) meeting a tiger on a journey-- "wild pointer"
Concept: a wild pointer means that the position that the pointer points to is unknown (random, incorrect, unlimited) if the pointer variable is not initialized at the time of definition, its value is random, and the value of the pointer variable is the address of another variable. it means that the pointer points to a variable whose address is uncertain, and dereferencing at this time is to access an uncertain address, so the result is unknown.
1.1 cause of formation of wild pointer 1. Pointer not initialized
two。 Pointer out of bounds access
3. Space release pointed to by pointer
The content of this section will be explained when dynamic memory is opened up, and here is a simple hint.
1.2 skillful laws and regulations to avoid the wild pointer
Pointer initialization (should be initialized to NULL when you don't know where to point)
Watch out for the pointer crossing the line.
The pointer points to the space to release the NULL even though.
Check the validity before using the pointer
(II) pointer operation 2.1 pointer +-integer
2.2 pointer-pointer
What is the result of the following code?
The final result is the number of elements between the two pointers.
Small supplement in class (using pointer-pointer to realize strlen)
(III) pointers and arrays
3.1 Array name
What is the name of the array? Let's look at an example.
It can be seen that the array name is the same as the address of the first element of the array.
Conclusion: the array name represents the address of the first element of the array.
So it's possible to write code like this:
Since the array name can be stored in a pointer as an address, it is possible for us to use the pointer to access one.
For example:
So pairi actually calculates the address of the array arr subscript I.
Then we can access the array directly through the pointer.
As follows:
3.2 Secondary pointer
A pointer variable is also a variable. If a variable has an address, where is the address of the pointer variable? This is the secondary pointer.
3.3 pointer array
Is the pointer array a pointer or an array?
The answer is an array. Is an array of pointers.
Array we already know about shaping array, character array.
What about the pointer array?
This is the end of the article on "what is the wild pointer in C language". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.