Structures (records)


struct person {
....char name[20];
....int age;
....int height;
....} aPerson;

....aPerson.height = 72;
....if (aPerson.age>30) distrust(&aPerson);

Select fields with a dot (like Pascal).
Don't pass structures in and out of procedures, pass pointers to structures.

struct listnode {
....int value;
....struct listnode *next;
....};

struct listnode *header, *p;
int key;

/* search a linked list */
....p = header;
....while (p->value != key)
........p = p->next;

Structures may contain pointers to structures.
Dereference and select using -> operator (like Pascal ^.).

struct dlistnode {
....int value;
....struct dlistnode *prev;
....struct dlistnode *next;
....};

typedef struct dlistnode *DLIST;

/* insert *newnode before *p in a doubly-linked list */
DLIST p, newnode;
....newnode->next = p;
....newnode->prev = p->prev;
....p->prev->next = newnode;
....p->prev = newnode;

Use typedef to shorten and clarify program text, and to hide details of a
....representation.
By convention, user-defined type names are all caps.