Call by Value and Call by Reference
[B][COLOR=DarkRed][FONT=Arial]Call by Value and Call by Reference[/FONT] [/COLOR][/B]
In this tutorial you will learn about C Programming - What is difference between call by value and call by reference in function?
[FONT=Verdana][SIZE=2]The arguments passed to function can be of two types namely[/SIZE][/FONT][INDENT] [FONT=Courier New][SIZE=2][COLOR=#800000]1. Values passed
2. Address passed [/COLOR][/SIZE][/FONT][/INDENT]
[FONT=Verdana][SIZE=2]The first type refers to call by value and the second type refers to call by reference.[/SIZE][/FONT]
[FONT=Verdana][SIZE=2]
[/SIZE][/FONT]
[FONT=Verdana][SIZE=2]For instance consider [B]program1[/B][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][B][URL="http://www.exforsys.com/tutorials/c-language/call-by-value-and-call-by-reference.html"]Read More...[/URL]
[/B][/SIZE][/FONT]
Re: Call by Value and Call by Reference
It was useful information about passing arguments to functions. In call by value argument gets passed as variables and in call by reference address gets passed. Does it mean if we use call by reference the execution time would be faster for the function since we the address gets accessed directly. If not why is it so?
Re: Call by Value and Call by Reference
call by value:
fun(5);
call by reference
fun(&a);
definition call by value
int fun(int a)
{
int b;
b= a+ 2;
return(b);
}
call by reference
int fun(int *a)
{
b=(*a )+ (*a)
return b;
}