C + +: A reference to a pointer and pointer to an ascending _ pointer

Source: Internet
Author: User

write 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 pointers

  

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 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 to Pointers

  

Brief Description:

Pointer reference, where the two pointers are essentially identical, and the p 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.