User manual
mikroC PRO for dsPIC
MikroElektronika
217
Structure Member Access
Structure and union members are accessed using the following two selection operators:
- . (period)
- -> (right arrow)
The operator . is called the direct member selector and it is used to directly access one of the structure’s members.
Suppose that the object s is of the struct type S and m is a member identier of the type M declared in s, then the
expression
s.m // direct access to member m
is of the type M, and represents the member object m in S.
The operator -> is called the indirect (or pointer) member selector. Suppose that the object s is of the struct type S and
ps is a pointer to s. Then if m is a member identier of the type M declared in s, the expression
ps->m // indirect access to member m;
// identical to (*ps).m
is of the type M, and represents the member object m in s. The expression ps->m is a convenient shorthand for
(*ps).m.
For example:
struct mystruct {
int i;
char str[21];
double d;
} s, *sptr = &s;
...
s.i = 3; // assign to the i member of mystruct s
sptr -> d = 1.23; // assign to the d member of mystruct s
The expression s.m is lvalue, providing that s is lvalue and m is not an array type. The expression sptr->m is an lvalue
unless m is an array type.