previous | index | next

Using the Deferencing Operator

Since g is a pointer, we can't use, for example,
  g.pile1
to access a member. We have to dereference the pointer first.

However,

  *g.pile1
will not work because the member operator '.' has higher precedence than '*'.

So

  (*g).pile1
will work. Now,

void clear(gameState *g) {
  (*g).pile1 = 0;
  (*g).pile2 = 0;
}

will succeed in modifying the original struct.


previous | index | next