How to return a reference in c ?

Total Post:134


 1367  View(s)
Rate this:
Hi Expert,

How to return a reference in c++?

Thanks in advance. 
  1. Re: How to return a reference in c ?

    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.


    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

      Modified On Mar-30-2018 03:54:54 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.