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;

Related Posts:

  • Inline function in C++ *Inline - function:-  To Eliminate the cost of calls to small functions, c++ proposes a new feature called Inline Function.             An inline function is a function that is expa… Read More
  • Scope resolution operator in C++ Scope resolution operator in C++ Scope resolution operator (::) in C++ programming language is used to define a function outside a class or when we want to use a global variable but also has a local variable with… Read More
  • // c++ program to check given no. is odd or even using class // c++  program to check given no. is odd or even using class    By Amit raj purohit http://codevidyalay.blogspot.com #include<iostream> using namespace  std; class number { private: … Read More
  • Calculate area using class ... // c++ program to calculate area using class              By Amit raj purohit http://codevidyalay.blogspot.com #include<iostream> using namespace std; class  shape { pr… Read More
  • Age using class   // cpp program to display age using class          By Amit purohit http://codevidyalay.blogspot.com #include<iostream> using namespace std; class person { char name[10]; int a… Read More

Translate

Popular Posts