Cpp - Pointer Indirection Operator

Using Pointers to Access Objects

The indirection operator * is used to access an object referenced by a pointer:

Given a pointer, ptr, *ptr is the object referenced by ptr.

You must always distinguish between the pointer ptr and the addressed object *ptr.

Example

long  a = 10, b,      // Definition of a, b 
      *ptr;            // and pointer ptr. 
ptr = &a;             // Let ptr point to a. 
b = *ptr; 

This assigns the value of a to b, since ptr points to a.

The assignment b = a; would return the same result.

The expression *ptr represents the object a, and can be used wherever a could be used.

The indirection operator * has high precedence, like the address operator &.

Both operators are unary, that is, they have only one operand.

Related Topic