Thursday, October 16, 2014

using return by reference C++



Prog 13: Write a program to find max value using return by reference.

#include<iostream.h>
#include<conio.h>
int &max(int *,int *);
int &max(int &a,int &b)
{


if(a>b)
return a;
else
return b;

}

void main()
{
int m,n;
clrscr();
cout<<"enter the value of m:";
cin>>m;
cout<<"enter the value of n:";
cin>>n
max(m,n)=100; 
cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;


getch();
}

Output:

enter the value of m:3 enter the value of n:5 m=3
n=100

No comments: