Professional Documents
Culture Documents
Parameter Passing
Parameter Passing
Parameter Passing
PASSING
METHODS
TYPES
Parameter passing :Giving data's
from calling function to called
function .
Call by value
Passing copy of the variable
Call by reference
Passing address of the variable
CALL BY VALUE
While Passing Parameters using call by
value , xerox copy of original parameter
is created and passed to the called
function.
Any update made inside method will not
affect the original value of variable in
calling function.
{
int temp;
temp = x;
x = y;
y = temp;
}
Output
a= 50
b=70
CALL BY REFERENCE
While passing parameter using call by
reference (or call by address) scheme , we
are passing the actual address of the
variable to the called function.
Any updates made inside the called
function will modify the original copy,
since we are directly modifying the content
of the exact memory location.
Call by value
#include <stdio.h>
void addvalue(int );
int main()
{
int a=10;
printf(\n a = %d before
function call", a);
addvalue(a);
printf(\n a = %d after
function call", a);
return 0;
}
void addvalue(int x)
{
x += 10;
printf(\n Inside addvalue
function , x = %d , x);
}
output
a = 10 before function call
Inside addvalue function x =20
a = 10 after function call.
Call by reference
#include <stdio.h>
void addvalue(int* );
int main()
{
int a=10;
printf(\n a = %d before
function call", a);
addvalue(&a);
printf(\n a = %d after
function call", a);
return 0;
}