C Programming Tutorial
Computer Tutorial

Call by Value



Call by Value

The call by value method copies the value of an argument into the formal parameter of the subroutine. In this case, changes made to the parameter have no effect on the argument.

A Program to demonstrate call by value

\* C Program to demonstrate call by value *\
# include < stdio.h >
int  sqr (  int x) ;
int   main( )
{

int   t = 10  ;
printf(" %d %d ",  sqr(t), t) ;
return ( 0 ) ;

}
int  sqr (  int x
{

x = x * x   ;
printf(" %c ",  name[i]) ;
return ( x ) ;

}

Output :

100 10
The value of the argument to sqr( ), 10, is copied into the parameter x. When the assignment x = x*x takes place, only the local variable x is modified. The variable t, used to call sqr ( ), still has the value 10. Hence, the output is 100 10.