1 2 3 4 5 6

*

A slightly different syntax is used for pointers to structures, for example

struct Person* ptr;

*The variable ptris now a pointer to a structure of type
Person. From our previous knowledge about pointers
we can use the following to get the value of the first
element of the structure that is accessed via ptr either
(*ptr).first
or
ptr->first

*

Thus (*ptr).is equivalent to ptr->
The -> operator takes a pointer to a struct, follows the pointer to the structure value and then extracts the field--this is a shorthand, but it makes sense

We can have arrays of structures, just as we can have arrays of any other data type. This is often quite convenient, and is done in the following way:

*

January 24, 1999

Page 3

copyright University of Alberta