References

References have been invented to use pointer functionality in a safer way.

References are mostly used in function arguments, see section 4.1.

// g++  tst.cpp

#include <iostream>

using namespace std; 

main()
{
  int i = 5; 
  int j = 7;
  int& j_ref = j;
  fprintf( stdout, 
		   " j_ref %d, &j_ref 0x%x, j %d, &j 0x%x \n", j_ref, &j_ref, j, &j);
  //
  // output: j_ref 7, &j_ref 0xbfabda14, j 7, &j 0xbfabda14
  //

  //
  // the following statement does not change j_ref but the 
  // object (j) which it is pointing to
  //
  j_ref = i;
  fprintf( stdout, 
		   " j_ref %d, &j_ref 0x%x, j %d, &j 0x%x \n", j_ref, &j_ref, j, &j);
  //
  // output: j_ref 5, &j_ref 0xbfabda14, j 5, &j 0xbfabda14
  //
}