Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Returning by reference

Status
Not open for further replies.

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;
}
 

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
Hi

I can't understand these two lins

emp &fun();
fun() = e2;


2nd I think there's no need to return e1;



Salam
Hossam
 

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
emp &fun();
fun() = e2;

This is an example program for returning by reference

emp &fun(); /* is the prototype declaration. &fun() is used in place of conventional
way of calling the function fun().*/
fun() = e2; /* when the calling function uses reference operator "&", the function call
call can exist even on the receiving side of the assignment.

By all means,return statement is needed.

Regards
Pradeep
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top