1 2 3 4 5

We know that a pointer to a float data object is declared as
follows:
float* p;


Thus the formal definition of the swap function must be:


void swap ( float* p, float* q ) {
float tt;
tt = *p;
// p is a pointer, *p is the value
*p = *q;
*q = tt;
}
To access the data object referenced by a pointer, use the
dereferencing operation *,as in


*p = *p + 1;adds 1 to the contents of p, as does
p[0] = p[0] + 1;
while
p[0] = p[1];is the same as
*p = *(p + 1);
p is incremented by the size of the object.


But what about
*p = *(p++);

  • It is important to remember that a pointer is an address
    of an object of a certain type. You must keep track of the
    type_sizewhen you are manipulating addresses of objects,
    and when manipulating the objects themselves
    .

January 26, 1998

Page3

JH/TM

[CONVERTED BY MYRMIDON]