We have just seen how to assign an address to a pointer variable by using another variable's named location, as follows:
int height;
int width;
int length
int* pDimension;
pDimension = &height;
A diagram of the memory layout for these declarations is given in the Accessing pointer targetssection.
We could later reassign pDimension, as follows:
pDimension = &width;
This assigns the address of width to thepDimensionvariable.widthand*pDimensionare now the same memory address. The target ofpDimensionis nowwidth.
Each time we assign an address to pDimension, it is the address of an already-defined variable identifier, as follows:
pDimension = &height;
// Do something.
pDimension = &width;
// Do something else.
pDimension = &length;
// Do something more.
pDimension = &height;
First, we make height the target of pDimension, then width, then length. Finally, we set height...