C + +: A reference to a pointer and pointer to an ascending _ pointer
◇ written in front
Today, when I was using pointers, I found a mistake of my own.
I just started thinking that the output of the two P are 6, at the time that two P refers to the same address, to modify the changes are all modified.
This is a very low-level error, two P refers to the same address, but the address of the two pointers is not the same.
Like two people know how to go to the railway station, but can not say that the two people is a person, not to mention in the revision of a person has forgotten the train station, it only know how to go to the high-speed railway station, the other only know the station is not affected, he still only know the railway station.
OK, so how do I change the p inside the main? There are two techniques to use:
- Pointer to pointers
- Reference to Pointers
◇ Pointer to hands
Brief description:
Pointer pointer technology, we want to modify what a pointer refers to, we need to pass the address of the pointer itself as a parameter to the method.
For example, we want to go to the railway station, only one person knows the location of the railway station, we want to find the railway station, according to an address to find this person, and then according to this person to find the railway station.
It means **p=& (& (P)), &p is the railway station. & (& (P)) is the address of the person who knows the station.
We want to revise p, we must find it first, find the address of the railway station after the change, the person will know the new station address.
◇ Reference of the pointer
Brief description:
Pointer reference, where the two pointers are essentially identical, and thep inside The change is the p in main. So the direct modification is good.
Personal understanding, reference is a variant of the pointer, that is, & can also be understood as *.
C + +: A reference to a pointer and pointer to an ascending _ pointer