Reference Variable
References
C++ added the so-called references variables.A references is an alias,or an alternate name to exiting variable.
The main use of references is acting as function formal parameters to support pass-by-reference. In a reference variable is passed into a function are rejected outside the function, the function works on the original copy. Changes inside the function are reflected outside the function.
A reference is similar to pointer.In many cases, a reference can be used as alternative to pointer, In particular for the function parameter.
References(&)-
C/C++ use & to denote the address of operator in an expression. C++ assign an additional meaning to & in declaration to declare a reference variable.
Syntax:
type &newName = existingName;
//or
type& newName = existingName;
//or
type & newName = existingName;
"newName is reference to existingName", or "newName is an alias of existingName". Now refer to the variable as newName or existingName.
Comments
Post a Comment