A human being is a part of a whole, called by us _universe_, a part
limited in time and space. He experiences himself, his thoughts and
feelings as something separated from the rest... a kind of optical
delusion of his consciousness. This delusion is a kind of prison for
us, restricting us to our personal desires and to affection for a few
persons nearest to us. Our task must be to free ourselves from this
prison by widening our circle of compassion to embrace all living
creatures and the whole of nature in its beauty.

— Albert Einstein

C++ Reference vs Pointer

Being C/C++ programmer does necessary mean to use References and Pointers. So what are this mystic programming entities :)?

In my point of view we can see answer 2 ways: (2X2)

  • Reference as data type
  • Pointer as data type
  • Reference as operator
  • Pointer as operator

And the best by example answers:

Reference as data type


1: int iVar=123;
2: int& iVarCpy = iVar;

1: We declared variable iVar to be of data type integer and we assigned value 123.
2: Declared that variable iVarCopy is integer reference thus address and value of iVarCpy will be the same as address and value of iVar.

Pointer as data type


1: int iVar=123;
2: int* iVarCpy = &iVar;

2: We declared that variable iVarCopy is integer pointer thus this variable holds an address as a value and we assigned the address of iVar to iVarCpy.

Reference as operator


1: int iVar=123;
2: cout << "The address of iVal is: " << &iVal;

2: the expression "&iVal" is returning the address of iVal.

Pointer as operator

We can apply the pointer operator only to variable which is of "Pointer as data type" thus "int*".


1: int iVar=123;
2: int* iVarCpy= &iVar;
3: cout << "The variable of *iValCpy is: " << *iVarCpy;

3: The expression *iVarCpy will give us the same value as iVar. We can say that
*iVarCpy == iVar and iVarCpy == &iVar thus &iVarCpy != &iVar