What is parameter passing and explain various methods of parameter passing?

The communication between a calling and called procedure is done by means of non-local names and parameters. The common methods for associating actual parameters with the formal parameters are:

Call by value:

This is the simplest method of parameter passing. The calling procedure evaluates the actual parameter and passes their resulting values to the called procedure which is a formal parameter as a local name and keeps these values in the storage for the formal parameter in the activation record of the called procedure. We may note that the operation in the formal parameters does not affect the value inactivation record of the column.

Call by reference:

When parameters are passed by reference (also known as call by address or call by location). The caller pass to the called procedure a pointer to the storage address of each actual parameter. In this case, the activation record of the caller always modified by the called procedure.

Copy restore:

Copy restore is a hybrid of call by value and call by reference. This method is also known as copy-in copy-out. These actual parameters are evaluated and the resulting values are passed to the called procedure. This step copy-in the value of actual parameters into the storage of formal parameters in the activation record of the called procedure. After execution, the current value of formal parameters are copied back into the address of the actual parameter is called copy-out, the final values of the formal address into the activation record of the calling procedure. This procedure is a hybrid between call by value and call by reference.

Call by name:

Call by name is traditionally defined by the copy rule of ALGOL which is: The procedure is treated as if it works a macro that is its body is substituted for the call in the column with the actual parameter substituted for the formals. Such a substitution is called  Macro Expansion or inline expansion.

This local name of the called procedure is kept distinct from the name of the calling procedure. The actual parameters are surrounded by parenthesis if necessary to preserve their integrity.

Leave a Reply