Functions - Methods of passing arguments

Methods of passing arguments:
 
Argument are variables through which we send value to functions during the function call. There are two method to pass arguments to the function, they are as follows

  1. Pass By Value
  2. Pass By Reference

1. Pass By Value : 
              In this method we pass the copy of actual argument's value to formal arguments. Hence formal arguments are another set of variables created in memory to hold these values. There are no link between actual and formal arguments. If the change in value of a formal argument in a function  will not effect the actual argument. Because they are two independent copies.

In the previous examples of Add() function the values are sent by Pass By Value   method.

2. Pass By Reference :
               In this method instead of passing a copy of actual argument's value, we pass the memory address of the actual argument to formal arguments. Hence formal argument receives the memory address and it will be received by pointer variable. Now pointer variable holds the address of actual argument hence any changes to these values will be directly effected to actual argument. 

Comments