What is Call by reference method?

In call by reference method addresses of the variables in memory are send at the time of function call rather than their values. Due to this any changes made by the function are reflected in the original variables.

Eg: Program of swapping values of two variables by using call by reference method
Void swap (int *c,int *d)
{
int temp;
temp=c;
c=d;
d=temp;
}
Void main ()
{
int a=10,b=20;
swap (&a, &b);
printf(“Value of a is %d \n value of b is %d”,a,b);
getch();
}
Output:
Value of a is 20 value of b is 10

More Questions

Leave a Reply

Word Verfication * Time limit is exhausted. Please reload CAPTCHA.