Call By Value And Call By Reference:-
1- Call By Value-:
- In call by value each of the actual arguement in the calling function is copied to the formal arguement.
- The change made in the formal arguement have no effect on the values of actual arguement in calling function.
2- Call By Reference-:
- In call by reference the address of actual arguement in the calling function is copied to the formal arguement.
- The change made in the formal arguement, made change on the values of actual arguement in calling function.
img credit: google image |
#include<stdio.h>
#include<conio.h>
main()
{int x=0,y=0,res=0;
printf("Enter the value of x and y:-");
scanf("%d %d ",&x,&y);
printf("\n x=%d,y=%d"x,y);
res= swap_value(intx,inty)
printf("\n Now x=%d y=%d"x,y);
getch();
}
int swap_value(intx,inty)
{int t=0;
printf("\n here x=%d y=%d",x,y);
t=x;
x=y;
y=t;
printf("\n now x=%d t=%d y=%d",x,t,y);
}
Output-:
Enter the value of x and y:-10
20
x=10 y=20
here x=10 y=20
now x=20 t=10 y=10
now x=10 y=20
please share the blogs of tech programiz
ReplyDelete