Fourth chapter pointer Pointer (Advanced)

Source: Internet
Author: User

Fourth Chapter

Pointer Pointer (advanced)


I hope beginners in the introduction, you can see some of the original English, I feel that English books is the original intention, and some now Chinese translation is added to some of the translator's understanding, how much is brought to the things, so some things I want to be able to follow their own.

&a is to take the location of a, we can copy this location to pointer variable.

*a "Extracting values" from the position referred to in a

Next, take an example first:

Algorithm Findbigger (x, y)

Pre:x, Y:: Reftointeger is valid references

Post:no Change to Data

Return:the reference to the larger of *x, *y

Reftointeger Temp

if (*x≥*y)

Temp←x

Else

Temp←y

End If

Return Temp

It is important to note that X and Y here refer to two address, which we can read from the two numbers to the value it refers to. When assigning a pointer temp, the value we enter for this pointer is the address of X.

This is true in the example of C + +:

int *findbigger (int *x, int *y) {

int *temp;

if (*x >= *y)

temp = x;

Else

temp = y;

return temp;

}

At this point, temp is storing the address.

Algorithm Swap (A, B)

PRE:A:: Reftointeger

B:: Reftointeger

A, b contain valid references

Post:the contents of *a and *b

is exchanged

Integer Temp←*a

*a←*b

*b←temp


Next, I'll talk about the use of memory and pointers.

Fourth chapter pointer Pointer (Advanced)

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.