20 Nov 2019

  • November 20, 2019
  • Amitraj
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:-

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;


Translate

Popular Posts