Reference Variable:-
A reference variable provides an alias (alternative name) for a previously defined variable.
1.) A pointer can be reassigned any number of time, while a reference variable cannot be reassigned after initialization.
2.) A pointer can point to NULL but reference variable always point to a value.
3.) We cannot take the address of reference variable like we can do with pointer variable.
Note: Some other properties of C++
Declaration of variable:
The C++ allows the declaration of variable anywhere in the program. Dynamic initialization of variable:
Variable can be initialized at runtime using expression at the place of declaration.
A reference variable provides an alias (alternative name) for a previously defined variable.
Syntax:
Data type & reference_name = variable_name;
Data type & reference_name = variable_name;
Ex:
int a=10;
int &b=a;
Comparative study of pointer & reference variable:-int a=10;
int &b=a;
1.) A pointer can be reassigned any number of time, while a reference variable cannot be reassigned after initialization.
2.) A pointer can point to NULL but reference variable always point to a value.
3.) We cannot take the address of reference variable like we can do with pointer variable.
Note: Some other properties of C++
Declaration of variable:
The C++ allows the declaration of variable anywhere in the program. Dynamic initialization of variable:
Variable can be initialized at runtime using expression at the place of declaration.
Ex:
int sum;
int a=sum;
int sum;
int a=sum;