Call By Value:
Creates a new memory loaction for use within the
subroutine.The memory is freed once it leaves the
subroutine.Changes made to the variable are not affected
outside the subroutine.
Call By Reference:
Passes a pointer to the memory location.Changes made to the
variable within the subroutine affects the variable outside
the subroutine.
IN CALL BY VALUE, BOTH THE ACTUAL AND FORMAL PARAMETERS
WILL BE CREATED IN DIFFERENT MEMORY LOCATIONS WHEREAS IF
THEY ARE CALLED BY REFERENCE BOTH WILL BE CREATED AT THE
SAME LOCATION.
in call by value method,a compiler get a copy of the
variable and thus changes made in the value in function
will not reflected back to the called function.but in call
by reference method,the compiler didn't get any copy ,but
actually it works on the original copy and thus changes
will be reflected back
call by value :
call by value means programmer send some value coping from
one function to another.At the time of function calling a
programmer can send a copy of variable of value.
call by referance :
it means sending sending the address of variable to the
called function means a user can send the address of variable.
simplest possible method of passing the parameters the
actual parameter are evaluated and their r values are passed
to the subroutine in location determined by the language
implimentation
call by value :
The copy of the argument is passed. e,g., if x and y are arguments and their corresponding values are say 100 and 200.
c=max(x,y);
max(inta,intb)
call by referance :
it is sending the address of variables to the called function.
IN CALL BY VALUE, BOTH THE ACTUAL AND FORMAL PARAMETERS
WILL BE CREATED IN DIFFERENT MEMORY LOCATIONS WHEREAS IF
THEY ARE CALLED BY REFERENCE BOTH WILL BE CREATED AT THE
SAME LOCATION ANDit is sending the address of variables to the called function .
call by value :
call by value means programmer send some value coping from
one function to another.At the time of function calling a
programmer can send a copy of variable of value.
call by referance :
it means sending sending the address of variable to the
called function means a user can send the address of
variable.
Call by value method:
passing the value of variable to the function.
void main()
{
int x=10,y=20;
printf("%d%d',x,y);
swap(x,y);
}
void swap(int a,int b)
{
int c;
c=a;//changes here do not affect in values
a=b;//of x and y in main function..
b=c;
}
call by reference method:
passing the address of variable to the function.
swap(&a,&b)
&c=&a;
&a=&b;
&b=&c;
changes made in subfunction causes changes in address of
variables n thus in main () also..
call by value is a technique whereby the called function
receives value from its calling function, stores this value
in its local arguments andd return a result.
call by reference is a technique whereby a calling gives
access of its local variables to the called function.