Home / Object Oriented Programming / Define Reference variable and Example

Define Reference variable and Example

Reference variable

A reference variable in C++ is a variable that acts an alias to another variable

Syntax:

data_type &ref_var = previous_var ;

Example:

int main(){

int x = 5;

int *p;

p = &x;

int &y = x;

y++

cout<<x<<endl<<*p<<endl<<p<<endl<<y<<endl;

return 0;

}