Variable references:
The role of a reference is to give the variable an individual name, if there is a variable a, want to give it an individual name B, you can write: int a;//defines a is an integer variable. int &b=a;//Declaration B is a reference.
The above is a reference to B , that is, B is the alias of a . The "&" above is a reference declarator and does not represent an address. A and B occupy the same address space and memory unit. Declaration B is a reference to a, which can be understood as: Make the variable B have the address of variable A.
Reference as a function parameter:
The reason why C + + increases the reference mechanism is mainly to use it as a function parameter to extend the function of data transfer.
There are two cases of function parameter passing:
1. Make the variable famous as an argument and formal parameter. This is the value of the variable passed to the parameter, and the pass is one-way. If the value of the parameter changes during the execution of the function, it is not passed back to the argument. Because when a function is called, the formal parameter and the argument are not in the same storage unit.
2. Pass a pointer to the variable. A parameter is a pointer variable, an argument is the address of a variable, and a parameter (pointer variable) points to a real parametric cell when the function is called.
3. The reference provides a method for a "variable parameter" for a function call.
Note: When the &a is preceded by a type (such as int &a), it must be a declaration of the reference, or the address of the variable if there is no previous type character (such as Cout<<&a).
C + + pointer reference variable reference