Contents    Page-10    Prev    Next    Page+10    Index   

Parameter Passing

Several methods of passing parameters between calling program and subroutine are used:

  1. 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.

  2. 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.

  3. Call by Value - Result: The value of the parameter is copied into the subroutine, and the result is copied back upon exit.

  4. 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.

  5. 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 changed.