References In C++
A reference variable is an alias, that is, another name for
an already existing variable. Once a reference is initialized with a variable,
either the variable name or the reference name may be used to refer to the
variable.
Fig: References In C++ |
Creating References in C++
Think of a
variable name as a label attached to the variable's location in memory. You can
then think of a reference as a second label attached to that memory location.
Therefore, you can access the contents of the variable through either the
original variable name or the reference.
Syntax:
Data_type
refenece variable variable name;
Example:
int i=18
Reference Example:
int& r=i;
Think of a
variable name as a label attached to the variable's location in memory. You can
then think of a reference as a second label attached to that memory location.
Therefore, you can access the contents of the variable through either the
original variable name or the reference.
Syntax:
Data_type
refenece variable variable name;
Example:
int i=18
Reference Example:
int& r=i;
No comments:
Post a Comment