C++
Reference Variables in C++
Types of Variables
int x=5;
int *p;
P = &y; // address of operator
int &y = x;
This means the reference (address) of x variable will be store in y variable.
int &y = x;
Note: The reference variable must be initialized at the time of Declaration.
Now at this time x and y are same.
e.g x=2 and y=2 are same
§ Reference means Address.
§ Reference variable is an internal pointer.
§ Declaration of Reference Variable is preceded with ‘&’ Symbol (but do not read it as ‘address of’).
§ Reference Variable must be initialized during the declaration.
§ It can be initialized with already declared variables only.
§ Reference variable cannot be update but pointer can be update.
e.g
Here the address of variable a will be increased but not be value.
But Reference variable will increase the value of that variable but not the address.
**You reached end of lecture**

Post a Comment
0 Comments