Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Parameter passing


There are two types of parameters:
  1. Formal parameters
  2. Actual parameters
Based on these parameters there are various parameter passing methods. 
The most common methods are:

1. Call by value:

  1. This is the simplest method of parameter passing. 
  2. The actual parameters are evaluated and their r-values are passed to called procedure. 
  3. The operations on formal parameters do not changes the values of actual parameter. 
Example: Languages like C, C++ use actual parameter passing method.

2. Call by reference:

  1. This method is also called as call by address or call by location.
  2. The L-value, the address of actual parameter is passed to the called routines activation record.
  3. The value of actual parameters can be changed. 
  4. The actual parameter should have an L-value. 
Example: Reference parameter in C++,PASCAL’S var parameters.

3. Copy restore: 

  1. This method is a hybrid between call by value and call by reference.
  2. This is also known as copy-in-copy-out or values result.
  3. The calling procedure calculates the value of actual parameters and it is then copied to activation record for the called procedure. 
  4. During execution of called procedure, the actual parameters value is not affected. 
  5. If the actual parameters have L-value then at return the value of formal parameter is copied to actual parameter. 
Example: In Ada this parameter passing method is used.

4. Call by name: 

  1. This is less popular method of parameter passing.
  2. Procedure is treated like macro. 
  3. The procedure body is substituted for call in caller with actual parameters substituted for formals. 
  4. The actual parameters can be surrounded by parenthesis to preserve their integrity. 
  5. The locals name of called procedure and names of calling procedure are distinct. 
Example: ALGOL uses call by name method.