Generally, pointers are the addresses in the memory. Different types of pointers represent the addresses of corresponding types of variables. The pointer itself also needs an address, so we can clearly define the pointer. The following is
Pointer and a pointer pointing to an integer pointer:
Int I = 1; <br/> int * Pi = & I; <br/> int ** Pi = & Pi
The values of each variable are output as follows:
I = 1 * Pi = 1 ** PPI = 1 <br/> & I = 0012ff60 Pi = 0012ff60 * PPI = 0012ff60 <br/> & Pi = 0012ff54 PPI = 0012ff54 <br /> & PPI = 0012ff48 <br/>
* PPI = 0012ff60 <br/> & (** ppi) = 0012ff60 <br/> * (& (* ppi )) = 0012ff60 <br/> * (& ppi) = 0012ff60
Because the address of the first element of the array name, the address pointer can also represent the array. A pointer can represent a two-dimensional array. A string pointer can be a string, and a pointer to a string can be a string set.
Determine the output of the following program:
Int main (INT argc, char * argv []) <br/>{< br/> const char * P = "12345 "; // P points to the first letter of string "12345" <br/> const char ** q = & P; // Q points to P, Q = & P <br/> * q = "ABCDE"; // means P points the first letter of "ABCDE" <br/> const char * s = ++ P; // s = p + 1; so * s = 'B' <br/> P = "xyzwvu "; // P points to the first letter of "xyzwvu" <br/> cout <* (++ s) <Endl; // ++ S; so * s = 'C' <br/>}
Note that in the third sentence of the program, the object pointed to by the pointer P is modified through its own pointer Q, so the final output is C.
In addition to the above, we can find that the stack in the memory increases in the direction of address reduction (why is it 12 bytes each time ?), You can also see that the values in each row are equal. PPI is a pointer to the integer pointer Pi, so PPI = & PI; Pi is an integer pointer to the integer variable I, so pi = & I.
Here we can see that the & (address operator, address-of operator) and * (dereference operator, dereference oprator) are inverse operations. As follows: