Dereference Operator - Other Syntax

Other Syntax

In BCPL, an ancestor of C, the equivalent operator was represented using an exclamation mark.

In C, there is syntactic sugar for accessing members of a struct or union, given a pointer to such. Given a pointer p to a structure s so:

*p = s

the usual way to access a member a is as s.a which, given the pointer, is expressed as (*p).a or can instead be accessed by the shorthand:

p->a

This can be chained; for example, in a linked list, one may refer to n->next->next for the second following node (assuming that n->next is not null).

Read more about this topic:  Dereference Operator