Structure and Union Operators

Structures and unions use operators to identify individual members. The membership operator is used with structures and unions, and the indirect membership operator is used with pointers to structures or unions.

The Membership Operator

. is used with a structure or union name to specify a member of that structure or union. If name is the name of a structure and member is a member specified by the structure template, then name.member identifies that member of the structure. The type of name.member is the type specified for member. The membership operator can also be used in the same fashion with unions.

Example

struct {
        int code;
        float cost;
} item;
item.code = 1265;

This statement assigns a value to the code member ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.