A reference variable is an alias for another variable. All reference variables must be initialized when declared. From then on, any changes made to the referenced variable will be made to the aliased variable. Reference variables are particularly important when passing variables to functions; this topic will be covered in more detail later, but here’s an example:

int x = 10; int& y = x; // declare y as reference to x. y = 4; // Changes the value of x to 4.

Microsoft Visual C++  .NET(c) Step by Step
Microsoft Visual C++ .NET(c) Step by Step
ISBN: 735615675
Year: 2003
Pages: 208 © 2008-2017.
If you may any questions please contact us: