+ 1
What is the use of reference variable and why we use it?
7 Answers
+ 6
E.g. to be able to pass it into a function and change its value there.
+ 4
A reference is not a variable!
Reference is like the c++ style pointers.
They act a bit similar but references are safer.
~ swim ~ explained well the difference.
Under the hood a reference is usually implemented with pointer but this is only compiler dependant.
Reference behaviour is well defined by the standards.
+ 4
~swim~ , sonic and AZTECCO
Thank you so much
+ 2
We can do it by pointer too then why we need it?
+ 1
rupali patel references allow you to write cleaner code,pointers make it hard to write elegant code plus they have lots of problems associated with them. Plus references help avoid passing copies of objects to functions,saving you space and time.Eg Passing a vector of 100M items to a function by copy can be avoided by using a reference.