View previous topic :: View next topic
|
Author |
Message |
varun kumar
New User
Joined: 20 Oct 2005 Posts: 1
|
|
|
|
what is the difference between call by value and call by reference. |
|
Back to top |
|
|
sairam
New User
Joined: 30 Aug 2005 Posts: 58 Location: Kolkata
|
|
|
|
Hi Varun
Call by value means the values will be passed in the calling function.The called function uses this values.The original variable doesnot change.It's value remain unchanged.
Ex
main function {
.
int a,b;
.
Call fun(a,b)
.
.
}
fun(int c,int d)
{
c=c+1;d=d+1;
}
here the changes of value will not be reflected in the variable passed as
parameter in calling function in main.
In case of call by reference the address of variable is passed,so change in the called function will be reflected in called function.
Hi if any doubt please let me know,i explained it shortly |
|
Back to top |
|
|
karthi_ind
Active User
Joined: 24 Feb 2004 Posts: 131 Location: Chennai
|
|
|
|
Hi Varun
This question has been answered so mny times.
Plz do search in the forum before ask questions.
Answer for ur question is
Parameters can be passed either by reference or conten(value).
If a paremeter is passed by reference both the called and calling program share the same storage space, so if any changes in the formal parameters (Called pgm parameters) will reflect in the actual paramers (calling pgm).
If a parameter is passed by content , calling and called do not share the same storage, so any changes in the called pgm will not reflect in the calling pgm . This is the difference.
Call by reference is default.
If you knw C language , thr is a concept called pointer which uses addressing. (means call by reference)
Corrections are welcome.
Karthi G. |
|
Back to top |
|
|
|