Contents
Page-10
Prev
Next
Page+10
Index
Parameter Passing
There are several methods of passing parameters
between calling program and subroutine:
- Call by Reference:
The address of the parameter is passed.
The storage of the actual parameter is used (and possibly modified).
Used by Fortran, Pascal for var parameters, C for arrays.
- Call by Pointer: A pointer to the parameter is passed by value.
Used in Lisp, in Java for reference types (any capital-letter type).
In some cases, parts of the object that is pointed to can be changed.
- 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. (Ada)
- Call by Name: The effect is that of a
textual substitution
or macro-expansion of the subroutine into the caller's environment.
Trouble-prone, hard to implement, slow. Used in Algol.