Search This Blog

Pages

Wednesday, January 12, 2011

Return by Reference

/*
* Return_by_reference.cpp
*
* Created on: Jan 12, 2011
* Author: bgsudeep
* This program is suitable when we need to give some value for the greater value among two values.
*/

#include<iostream.h>
int &max(int &a, int &b);
int main()
{
int x,y;
cout<<"Please input two numbers: "<<endl;
cin>>x>>y;
max(x,y)=10;
cout<<"x= "<<x; //Here if you put the value of x which is less than y then it will displays the value of x.
//If you put the value of x which is greater than y then it will displays the value 10.

return 0;
}
int &max(int &a, int &b)
{
if (a>b)
return a;
else
return b;
}

No comments:

Post a Comment