Program to demonstrate reference variable in C++

 //Program to demonstrate reference variable in C++

#include<iostream>

using namespace std;

int main()

{

    int num=10;

    int& x=num;//creating reference of num

    cout<<endl<<x;//value of x

    cout<<endl<<num;//value of num

    cout<<endl<<"address of num is "<<&num;

    cout<<endl<<"Address of x is "<<&x;//same as the address of num

}//end of main


OUTPUT :

10

10

address of num is 0x61fe14

Address of x is 0x61fe14

Comments