Several methods of passing parameters
between calling program and subroutine are used:
- Call by Reference:
The address of the parameter is passed.
The storage in the calling program is used (and possibly modified).
Used by Fortran, Pascal for var parameters, C for arrays.
- Call by Value: The value
of the parameter is copied into the subroutine. Modifications are not
seen by the caller. Expensive for large data, e.g. arrays.
Used in Pascal, Java, C for basic types.
- Call by Value - Result: The value of the parameter is copied into
the subroutine, and the result is copied back upon exit.
- Call by Name: The effect is that of a
or macro-expansion of the subroutine into the caller's environment.
Trouble-prone, hard to implement, slow. Used in Algol.
- Call by Pointer: A pointer to the parameter value is passed.
Used in Lisp, in Java for reference types. The object pointed to can be