decl-specifiers & cv-qualifier-listopt dname ;
A reference is a 16-bit or 32-bit quantity that holds the address of an object but behaves syntactically like that object. A reference declaration consists of an (optional) list of specifiers followed by a reference declarator.
In C++, any object whose address can be converted to a given pointer type can also be converted to the analogous reference type. For example, any object whose address can be converted to type char * can also be converted to type char &. No constructors or class conversion functions are called to make a conversion to a reference type.
Example
In the following example, the variable x
is passed by reference and modified by the AddIt
function.
// Example of the reference operator
void AddIt(int& x)
{
x += 2;
}
int x;
x = 3;
AddIt(x);
printf("%d, x) ; // the value of x is now 5