DrDolittle
Full Member level 3
- Joined
- Sep 24, 2004
- Messages
- 162
- Helped
- 5
- Reputation
- 10
- Reaction score
- 1
- Trophy points
- 1,298
- Location
- Within arm's reach
- Activity points
- 1,443
Please explain the need of "return" command in this program. This is an example program explaing returning by reference.
#include<iostream.h>
struct emp
{
char name[20];
int age;
float sal;
};
emp e1 = {"amol",21,2345.00};
emp e2 = {"ajay",23,4500.75};
void main()
{
emp &fun();
fun() = e2;
cout<<e1.name<<e1.age<<e1.sal;
}
emp &fun()
{
cout<<e1.name<<e1.age<<e1.sal;
return e1;
}
#include<iostream.h>
struct emp
{
char name[20];
int age;
float sal;
};
emp e1 = {"amol",21,2345.00};
emp e2 = {"ajay",23,4500.75};
void main()
{
emp &fun();
fun() = e2;
cout<<e1.name<<e1.age<<e1.sal;
}
emp &fun()
{
cout<<e1.name<<e1.age<<e1.sal;
return e1;
}