Confusing Structure-Member Operators

Two different operators are used to access the members of a structure. Use the structure-member operator (.) to access a structure member directly, and the pointer-member operator (–>) to access a structure member indirectly through a pointer.

For instance, you may create a pointer to a structure of the employee type,

struct employee *p_ptr;

and initialize the pointer to point to the jones structure:

p_ptr = &jones;

If you use the structure-member operator to access a structure member through the pointer,

p_ptr.months = 78; /* Error! */

QuickC issues this error message:

C2040: '.' requires struct/union name

Use the pointer-member operator to access a structure member through a pointer:

p_ptr->months = 78;