Chapter 4 Pointer pointer (advanced) and Chapter 4 Pointer pointer
Chapter 4
Pointer (advanced)
I hope that when beginners get started, they can read some original English books. I feel that English books are the original intent, while some current Chinese translations are the translator's understanding, so I want to be able to follow my own ideas.
& A is the location where A is stored. We can copy this location to pointer variable.
* A "extracts the value" from the position specified by"
First, take an example:
Algorithm findBigger (x, y)
Pre: x, y: refToInteger are valid references
Post: no change to data
Return: the reference to the larger of * x, * y
RefToInteger temp
If (* x ≥ * y)
Temp limit x
Else
Temp Policy
End if
Return temp
It is worth noting that x and y here refer to two addresses. We can read the values from these two numbers. When a pointer temp value is assigned, the value of this pointer is the address of x.
This is the case in the C ++ instance:
Int * findBigger (int * x, int * y ){
Int * temp;
If (* x> = * y)
Temp = x;
Else
Temp = y;
Return temp;
}
At this time, temp stores the address.
Algorithm swap (a, B)
Pre: a: refToInteger
B: refToInteger
A, B contain valid references
Post: the contents of * a and * B
Are exchanged
Integer temp limit *
* A branch * B
* B then temp
Next, I will talk about memory and pointer usage.