Reference types - Introducing
Ampersand & is used to:
represent the address-of operator for obtaining address of a variable
denote a reference to another variable (alias)
You declare a reference type using a syntax similar to declaring a pointer variable. That is, you declare the data type of the C++ variable or object that will be referred to, then you use the & character followed immediately by the reference type name. Finally, it's important to note that when declaring a reference, you must assign it at that time. It behaves similar to a constant in this sense. An example demonstrates the declaration.
To see how this affects the original value of num, let's create another small code sample that displays the value for num, modifies it through refNum, then outputs the memory addresses of num and refNum.
If we add the above code with :
Last updated