Issue
References are widely used in programming, especially to efficiently pass large or mutable data as arguments to procedures, or to share such data among various uses. A reference may point to a variable or record that contains references to other data. This idea is the basis of indirect addressing and of many linked data structures, such as linked lists.
Resolution
There are many advantages of using variables reference over pointer variables (like in C++ programming) such as:
- A reference variable does not consume any extra memory. It has the same memory address as the variable it refers to. While a pointer needs extra space for itself.
- In order to access the value of the referenced variable using pointer, we need to use a dereferencing operator whereas we can do the same using reference variable without any dereferencing method.
Reference variables are cleaner and modish as compared to the pointers; they can also be used while passing in the function as arguments, known as call by references.
Disclaimer
The views and opinions expressed in this article are those of the author(s) and do not necessarily reflect the official policy or position of Schneider Electric.