Anonymous user
Parameter Passing: Difference between revisions
m
English, clarified formal and actual parameter
(Created) |
m (English, clarified formal and actual parameter) |
||
Line 1:
[[Category:Encyclopedia]]Parameters of a subprogram refer to its arguments and results
* by value (or else by copy)
* by reference
When the parameter is passed by value, within the subprogram the object denoted by the formal parameter (the identifier of the parameter) is distinct from the object of the actual parameter (the value that has been passed in). In particular, the formal parameter has an independent set of states, so that if the object is mutable, then updates
When the parameter is passed by reference, the formal object represents an aliased view of the actual object. Thus, updates of the formal object are instantly reflected by the actual object.
The mutability of the parameter is independent on the parameter passing mode. In general the formal parameter can have any of three access modes:
Line 16:
For example, when an in-out parameter is passed by value, the compiler creates a copy of it and makes the copy available to the subprogram. After the subprogram completion, the value of the copy is written back to the actual object.
The language's
===Example [[Ada]]===
[[Ada]] uses both by value and by reference passing and all three parameter access modes:
*
*
* for all other types the choice is left to the compiler.
===Example [[C]]/[[C++]]===
[[C]]
===Example [[Fortran]]===
|