ADVERTISEMENT
ADVERTISEMENT

Home » C++ programs » C++ basic programs

C++ program to demonstrate use of reference variable

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.