
Returning More Values by Reference 217
int & large (int & p, int & q);
int main()
{ clrscr();
int l,k;
cout<<“\n Enter values of l and k: ”;
cin>>l>>k;
large (l,k)=120;
cout<<“ l= ”<<l << “ k=”<<k;
return 0;
}
int & large (int & p, int & q)
{
if (p>q) return p;
else return q;
}
OUTPUT
Enter values of l and k : 4 8
l= 4 k=120
Enter values of l and k : 9 2
l= 120 k=2
Explanation: In function main(), the statement large (l, k) = 120 calls the function large().
It returns reference to the variable containing larger value and assigns the value 120 to it. The
return type of function large() is int ‘&’ (reference), it indicates that the call to function ...