References
References
Creating References
A reference variable is a "reference" to an existing variable, and it is created
with the & operator:
Now, we can use either the variable name food or the reference name meal to
refer to the food variable:
Example
string food = "Pizza";
string &meal = food;
Memory Address
In the example from the previous page, the & operator was used to create a
reference variable. But it can also be used to get the memory address of a
variable; which is the location of where the variable is stored on the computer.
To access it, use the & operator, and the result will represent where the variable
is stored:
Example
string food = "Pizza";
Note: The memory address is in hexadecimal form (0x..). Note that you may not
get the same result in your program.
These two features are one of the things that make C++ stand out from other
programming languages, like Python and Java.