Working with Pointers and Structures 245Figure 11.3 Structure containing pointers.This defines a structure called entry, which contains two members.The first member of
the structure is a simple integer called value.The second member of the structure is a
member called next, which is a pointer to an entrystructure.Think about this for a
moment. Contained inside an entrystructure is a pointer to another entrystructure.
This is a perfectly valid concept in the C language. Now suppose you define two vari-
ables to be of type struct entryas follows:
struct entry n1, n2;
You set the next pointer of structure n1to point to structure n2by executing the fol-
lowing statement:
n1.next = &n2;
This statement effectively makes a link between n1and n2, as depicted in Figure 11.4.
pointersp1
p2100-97i1i2n1value
nextn2value
nextFigure 11.4 Linked structures.