A “member-selection expression” refers to members of structures and unions. Such an expression has the value and type of the selected member.
Syntax
postfix-expression . identifier
postfix-expression –> identifier
This list describes the two forms of the member-selection expressions:
The two forms of member-selection expressions have similar effects.
In fact, an expression involving the member-selection operator (–>) is a shorthand version of an expression using the period (.) if the expression before the period consists of the indirection operator (*) applied to a pointer value. Therefore,
expression –> identifier
is equivalent to
(*expression) . identifier
when expression is a pointer value.
Examples
The following examples refer to this structure declaration. For information about the indirection operator (*) used in these examples, see Indirection and Address-of Operators.
struct pair
{
int a;
int b;
struct pair *sp;
} item, list[10];
A member-selection expression for the item
structure looks like this:
item.sp = &item;
In the example above, the address of the item
structure is assigned to the sp
member of the structure. This means that item
contains a pointer to itself.
(item.sp)–>a = 24;
In this example, the pointer expression item.sp
is used with the member-selection operator (–>) to assign a value to the member a
.
list[8].b = 12;
This statement shows how to select an individual structure member from an array of structures.