A function can return a reference.Returning a reference can be very useful when you are overloading certain types of operators.
However,it also can be employed to allow a function to be used on the left side of an assignment statement.
e.g.
int &f( )//return a reference int x; int main( ) { f( )=100; //assigning 100 to reference returned by f() cout<< x <<"\n"; return 0; } //return an int reference. int &f() { return x; //return a reference to x }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Can you answer this question?
Write Answer1 Answers