Reference
Variable:
A reference variable provides an alias (alternative
name) for a previously defined variable.
Syntax:
Data type & reference_name = variable_name;
Ex:
int a=10;
int &b=a;
Comparative
study of pointer & reference variable:
i.
A pointer can be reassigned any
number of time, while a reference variable cannot be reassigned after
initialization.
ii.
A pointer can point to NULL but
reference variable always point to a value.
iii.
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;
0 comments:
Post a Comment