Monday, 3 December 2018

What is difference between normal variable and reference variable in c++? tccicomputercoaching.com

A reference variable is an alias, that is, another name for an already existing variable in C++ . Once a reference is initialized with avariable, either the variable name or the reference name may be used to refer to the variable .



They can be used like normal variables. '&' operator is needed only at the time of declaration. Also, members of an object reference can be accessed with dot operator ('.'),

For example,

int amount =10;
int rupees;
rupees=&amount;
cout<<"rupess"<< rupess;
cout<<"amount"<< amount;
output:
rupess 10
amount 10
now we do any update in amount variable , it will affect also in rupees variable. Same for vice versa.
for example,
amount=amount + 20;
cout<<rupess;

output: 30

To learn more about variable, data types , C++ Language , Operators.

Join TCCI in Bopal and Satellite in Ahmedabad.

You can Join TCCI online Coaching Class .

Call us@ 98256 18292

Visit us @ http://tccicomputercoaching.com/blog/

No comments:

Post a Comment