Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

Difference Between Call By Value And Call By Reference

 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


Example-:
#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
  



Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey