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)