OOPS8 Reference
OOPS8 Reference
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.
y
The basic syntax to create a reference is -
u d
S t
The newly created variable will now refer to the previous variable.
For example -
D
J M
int i = 17 // The variable i is declared as 17
C++ code
#include <iostream>
int main () {
i = 5;
d y
d = 11.7;
tu
S
cout << "Value of d : " << d << endl;
D
M
return 0;
J
Difference between Reference and Pointers
References Pointers
A reference assigned to a particular object Pointers, on the other hand, can point to different
cant be changed. objects at any time.
A reference is also initialized at the time of Pointers can be initialized at any time.
its creation.