1 2 3 4 5

Keep in mind what you want to do with the pointer.

  • Do you want to assign itto another pointer, or to
  • pass itas a pointer argument?
  • Do you want to dereference it (follow it) and work with
    the object that it points to?


Review the examples pointers-1.c and its associated output pointers-
1.log, and pointers-2.c and its associated output pointers-2.log. See
class handout and online notes.


Arrays and Pointers(continued)

  • C really does not have arrays. C has contiguous
    regions of identical objects with a base pointer.
    Array
    notation is simply a form of pointer shorthand.


Given the two declarations:


float a[10];
float* pa;


The following pairs of notation are equivalent

&a[0]
a[i]
*(pa+i)

a
*(a+i)
pa[i]

the former is prefered
the former is prefered
the former is prefered

The usage should be consistent with the declaration

January 26, 1998

Page4

JH/TM

[CONVERTED BY MYRMIDON]