Home »
C++ programs »
C++ basic programs
C++ program to demonstrate use of reference variable
Learn about the reference variables in C++, how to declare and use them in our C++ program?
[Last updated : March 01, 2023]
C++ Reference Variables
Reference variable is the important and new concept in C++ programming language, the reference variables are used as a reference of existing variables i.e., reference variables are the alternative names of the existing variables.
In this program you will learn how to use reference variable in c++ programming language to make an alias of a variable.
Reference variable example in C++
/*C++ program to demonstrate use of reference variable.*/
#include <iostream>
using namespace std;
int main()
{
int a=10;
/*reference variable is alias of other variable,
It does not take space in memory*/
int &b = a;
cout << endl << "Value of a: " << a;
cout << endl << "Value of b: " << b << endl;
return 0;
}
Output
Value of a: 10
Value of b: 10