What is a reference variable?
A reference is defined as an alias for another variable. In short, it is like giving a different name to a pre-existing variable. Once a reference is initialized to the variable, we can use either the reference name or the variable to refer to that variable.
Creating references in C++
The basic syntax to create a reference is -
Data type& new variable = previous variable
The newly created variable will now refer to the previous variable.
For example -
int i = 17 // The variable i is declared as 17
Creating the reference of i will be as -
int& x = i // Here x will be called as the integer variable initialised to r
Difference between Reference and Pointers
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week