Call by Value Call by Referance
Call by Value Call by Referance
&
Call by Reference
Function
C Prog
Call by Value & Call by Reference
Address of
s=fnadd(a,b); a 1004 a=100
Address of b=200
} b 1016
int fnadd(int x,int y)
{ Address of x=100
int temp; x 3000
temp=x+y; Address of y=200
return temp; x 3020
}
#include <stdio.h>
void main()
{
int s,a,b;
int fnadd(int *,int *); 2. Call by reference: An address
printf("\n Enter two values : "); of the variable is passed to the function.
scanf("%d",&a);
scanf("%d",&b);
s=fnadd(&a, &b);
printf("\n Sum of given two values : =%d",s); Address of
a 1004 a=100
}
Address of b=200
int fnadd(int *x,int *y) b 1016
{
int temp; Address of 1004
temp=*x+*y; x 3000
return temp; Address of 1016
} x 3020
swapping of two numbers
Using call by value
#include<stdio.h>
int main() {
int a = 20;
int b= 68;
void swap(int, int); a=100
printf("The numbers before swapping a and b are %d %d \n",a, b);
b=200
swap(a, b);
printf("The numbers after swapping a and b are %d %d \n",a, b);
return 0;
} x=100 y=200
void swap(int x, int y)
y=200 x=100
{
int temp = x;
x = y;
y = temp;
}
swapping of two numbers
Using call by Reference
#include<stdio.h>