Pass by value and reference

Saturday, 6 April 2013

Pass by value:

  • Here the values of actual parameters are copied into the formal parameters of the function.
  • This can also means that the calling function sends a copy of each value to the called function.
  • In this method ,the changes of the formal parameters cannot affect the actual parameters.
/*Sample program on pass by value:*/


  • From this program it is clear that when ever value is passed to a function it cannot be modified in the called function.
Pass by Reference:


  • In Pass by reference method we are passing address to a called function.
  • when address is send to the function value at the address can be modified in the called function.
  • To modify value of a variable in a function send its address to the function.

/*sample program on pass by reference*/











No comments:

Post a Comment