Operations with pointers
At this point, the only operations that work reasonably with pointers are the following:
- Assignment
- Accessing pointer targets
- Limited pointer arithmetic
- The comparison of pointers
We will explore each of these in turn. As we do, we must also consider the NULL
special pointer value (the zeroth address), or a null
pointer, and the void*
special, unspecified pointer type, or a void
pointer type.
Assigning pointer values
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 targets section.
We can later reassign pDimension
, as follows:
pDimension = &width;
This assigns the address of ...