hey i was wondering exactly what a reference was in C++ and how to use so if u could help me id appreiciate it thanks
hey i was wondering exactly what a reference was in C++ and how to use so if u could help me id appreiciate it thanks
hooch
A reference is an alias for a variable. Look at the following code.
int number=7;
int &number2=number;
cout<<"Number is: "<<number<<endl;
cout<<"Number2 is: "<<numbers<<endl;
number2=number2+2;
cout<<"Number is: "<<number<<endl;
cout<<"Number2 is: "<<number2<<endl;
if this were compiled in a formal program, the output would be the following:
Number is 7
Number2 is 7
Number is 9
Number2 is 9
Basically, the reference is another name for the variable and anything done to either is done to both. Good luck and keep working!!
so basically its the same as assigning a varaible to another variable accept with a & sign in front it?
hooch