Sunday, 25 December 2011

c++ Reference Variable.

int x;   -> x is an integer variable.

int& y = x -> y is a reference to variable x. Ie. 'y' becomes alias name to 'x'.  Otherwords, same memory location is referenced by two variables.

Do not get confused with pointer. Consider following scenario:

int * const &z = &x;

Here What you are trying to say is that 'z' is a pointer reference to an address of x.




No comments:

Post a Comment