Home Segments Index Top Previous Next

313: Mainline

What you have learned about defining integer pointers applies to defining structure-object pointers as well:

struct trade t;      /* Allocate space for a trade */ 
struct trade *tptr;  /* Allocate space for a pointer to a trade */ 

The definition, struct trade *tptr; makes tptr a pointer variable, and the chunk of memory allocated for tptr contains the address of a chunk of memory allocated for a trade object.

Thereafter, tptr, without a dereferencing asterisk, refers to the location of the address; *tptr, with a dereferencing asterisk, refers to the location of the trade object identified by the address. Said more concisely, tptr's value is an address, whereas *tptr's value is a trade object.