C++ Syntax: Dereference: *


The dereference operator * takes a pointer to a value (variable or object) and returns the value. For example:-
Int_t   my_int = 2;
Int_t  *my_int_ptr = &my_int;
*my_int_ptr = 4;
my_int_ptr is a pointer to my_int. By dereferencing the pointer my_int is retrieved. In this example it is then assigned to so my_int receives the value 4.

See operator precedence

Other Uses for *

  1. When * after a type name (either a basic data type or a class) it means the the type is a pointer to that type, as shown in the above declaration of my_int_ptr. The logic is that the declaration:-
    Int_t  *my_int_ptr;
    states that *my_int_ptr is an Int_t, from which it follows that my_int_ptr must be a pointer to Int_t
  2. * is also an arithmetic operator.

Usage Notes

Go Back to the The C++ Crib Top Page

If you have any comments about this page please send them to Nick West