References

A C++ reference is an alias or an alternative name for an object. All operations applied to a reference act on the object the reference refers to. The address of a reference is the address of the aliased object.

A reference type is defined by placing the & after the type specifier. You must initialize all references except function parameters when they are defined.

Because arguments of a function are passed by value, a function call does not modify the actual values of the arguments. If a function needs to modify the actual value of an argument, the argument must be passed by reference (as opposed to being passed by value). Passing arguments by reference can be done using either references or pointers. In C++, this is accomplished transparently. Unlike C , C++ does not force you to use pointers if you want to pass arguments by reference. For example:

int f(int&);
void main()
{
      extern int i;
      f(i);
}

You cannot tell from the function call f(i) that the argument is being passed by reference.

References to NULL are not allowed.



Object


Passing Arguments by Reference
Pointers
Declarators
Initializers
Initializing References