previous | start | next

Dereferencing operator *

When used as a prefix operator, the * symbol is the dereferencing operator.

It should be applied to a pointer variable (or a pointer expression).

The result is an alias for what p is pointing to.

So *p in the example above is an alias for x.

Corrected Example:

      int x = 5;
      int y;
      int * p = &x;

      y = *p; // This is the same as y = x;
              // It assigns x's value 5 to y.

      *p = 6; // This is the same as x = 6;
              // p's value is unchanged; it is still the address of x
              // This changes x's value to be 6.
   


previous | start | next