In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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 the function of the second-level pointer of C language". In the daily operation, I believe that many people have doubts about the function of the second-level pointer of C language. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the question of "what is the function of the second-level pointer of C language?" Next, please follow the editor to study!
I. concept
In the following pointing relationship between A to B and B to C:
First
C is "a piece of content". For example, if you allocate a piece of memory with malloc or new, and then insert "a piece of content", that is C. The starting address of C is 0x00000008.
B is a pointer variable, which stores the address of C, but B also takes up space, so B also has an address. The starting address of B is 0x00000004, but the address of C is stored in B memory, so the content of B is 0x00000008.
So it's easier to understand so far:
B = 0x00000008; / / the content of B
* B = "a piece of content"; / / B dereference, that is, the value of C pointed to by the B pointer
& B = 0x00000004; / / B takes the address, and the address of B is 0x00000004
So, let's take a look at A:
An is a secondary pointer variable, in which the address of B, 0x00000004, also has an address, which is 0x00000000
* A = B = 0x00000008; / / A dereference is the content of B.
* * A = * B = "a piece of content"; / / B dereference, that is, the value of C pointed to by the B pointer
A = & B = 0x00000004; / / A stores the address of B and the address of B is 0x00000004
& A = 0x0000000000; / A fetch address
The pointer to the pointer, that is, the secondary pointer, holds the address of the primary pointer, such as:
P is the first-level pointer, which stores the address of a; Q is the pointer to the pointer (second-level pointer), which stores the address of the first-level pointer (p); the content of Q is the value of 0xbfaca 770 ~ Q, that is, the content 0xbfaca776 that Q points to, that is, * Q is still an address, that is, the content of pointer p, that is, * qqqp.
2. Use
The function of the second-level pointer as a function parameter: define a pointer p outside the function, assign a value to the pointer within the function, and take effect on the pointer p after the end of the function, then we need the second-level pointer.
Let's take a look at the following code: there are two variables, acentine b, and the pointer qmemery Q points to a, and we want Q to point to b, which is implemented in the function.
1. Let's first take a look at the implementation of the first-level pointer.
# includeusing namespace std;int a = 10 int b = 100 int * Q void func (int * p) {cout
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.