A pointer is a variable that holds an address. Using pointers to reduce data duplication and change raw data, you can also construct complex data structures such as linked lists and internal networks in memory.
Each computer architecture uses an address that has a fixed width, and it is important to see if an address is too large to fit on a particular machine.
At present, the physical memory of the computer has exceeded the addressing range of 32-bit address (more than 4 billion), need the operating system code to compensate for the gap. Sooner or later the 64-bit architecture becomes mainstream and will support near-infinite number of addresses.
In addition to arrays and classes, do not make assumptions about where the variables are in memory.
The asterisk operator is called an indirect operator.
int arr[5]; int* P=arr;//arr is a constant (it: pointer constant) that holds the address of the first element of an array, and the value cannot be changed, but the variable pointer p can get its value. C + + interprets array names as address expressions, arr[3] i.e. * (A+3)
Pointer arithmetic rules:
Address expression + integer
Integer + address expression
Address Expression-Integer
Address expression-Address expression
The size comparisons can be made between addresses (but the order of data types outside the array is not guaranteed in memory).
The compiler completes the following transformations:
New address = old address + (integer * base type unit length)
Using pointers is slightly faster than using array subscripts. In particular traversal, the pointer executes only two additions at a time (the loop variable increments and the pointer increments.) The faster method is to save the Pmax=p+len first, and then iterate through the condition is P<pmax, without the loop variable), and the array performs a multiplication and an addition.
It: Why pass in an array parameter to a function, often passing in the array size at the same time: only in this way can the array be processed completely.
To pass an array to the function, simply pass the name of the array. The function obtains the address of the first element and treats it as a pointer. It: Is there any difference between a function entry int* A and an int a[]? A is a constant pointer or a variable pointer?
* Same as + + priority, but they are all combined from right to left, so *p++ is equivalent to * (p++)
"Studious C + + 2nd Edition", chapter 4th pointers--I know where the data is.