HP C A.06.05 Reference Manual
Expressions and Operators
Structure and Union Members (., ->)
Chapter 5134
Structure and Union Members (., ->)
A member of a structure or a union can be referenced using either of two operators: the period
or the right arrow.
Syntax
postfix-expression . identifier postfix-expression -> identifier
Description
Use the period to reference members of structures and unions directly. Use the arrow operator
to reference members of structures and unions pointed to by pointers. The arrow operator
combines the functions of indirection through a pointer and member selection. If P is a pointer
to a structure with a member M, the expression P->M is identical to (*P).M.
The postfix-expression in the first alternative must be a structure or a union. The expression is
followed by a period (.) and an identifier. The identifier must name a member defined as part
of the structure or union referenced in the postfix-expression. The value of the expression is
the value of the named member. It is an lvalue if the postfix-expression is an lvalue.
If the postfix-expression is a pointer to a structure or a pointer to a union, follow it with an
arrow (composed of the - character followed by the |) and an identifier. The identifier must
name a member of the structure or union which the pointer references. The value of the
primary expression is the value of the named member. The resulting expression is an lvalue.
The . operator and the -> operator are closely related. If S is a structure, M is a member of
structure S, and &S is a valid pointer expression, S.M is the same as (&S)->M.