Pointer Reference or Pointer-to-Pointer

  

This one is about a hardcore Ansi-C++ topic. For many of us , pointers to pointers are subtle things. But a lurking C++ feature eases our life... 

  

#include 

using namespace std; 

  

// Pointer references , C++ style - new fashion

void increment(int*& i)

{

 i++;

  

// Pointers to Pointers , C style - old fahion

void decrement(int** i)

{

 (*i)--;

  

int main()

{

 int* i = 0;

 cout << "i = " << i << endl;

 increment(i);

 cout << "i = " << i << endl;

 decrement(&i);

 cout << "i = " << i << endl;

 return 0;

  

// The output is ;

// i = 00000000

// i = 00000004

// i = 00000000