Difference between revisions of "Parameter (computer programming)"
Karl Jones (Talk | contribs) |
Karl Jones (Talk | contribs) (→See also) |
||
Line 28: | Line 28: | ||
* [[Computer programming]] | * [[Computer programming]] | ||
* [[Computer science]] | * [[Computer science]] | ||
− | * [[Input (computing) | + | * [[Input (computing)]] |
* [[Parameter]] | * [[Parameter]] | ||
* [[Subroutine]] | * [[Subroutine]] |
Revision as of 18:24, 29 February 2016
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine.
Description
These pieces of data are called arguments.
An ordered list of parameters is usually included in the definition of a subroutine, so that, each time the subroutine is called, its arguments for that call can be assigned to the corresponding parameters.
Just as in standard mathematical usage, the argument is thus the actual input passed to a function, procedure, or routine, whereas the parameter is the variable inside the implementation of the subroutine.
For example, if one defines the add subroutine as def add(x, y): return x + y, then x, y are parameters, while if this is called as add(2, 3), then 2, 3 are the arguments.
Note that variables from the calling context can be arguments: if the subroutine is called as a = 2; b = 3; add(a, b) then the variables a, b are the arguments, not only the values 2, 3. See the Parameters and arguments section for more information.
In the most common case, call by value, a parameter acts within the subroutine as a variable initialized to the value of the argument (a local (isolated) copy of the argument if the argument is a variable), but in other cases, e.g. call by reference, the argument supplied by the caller can be affected by actions within the called subroutine (as discussed in evaluation strategy).
Call by value
In call by value, one can thus think of arguments as values (properly, think of the value of arguments as the "arguments" themselves), but in general arguments are not simply values.
Semantics
The semantics for how parameters can be declared and how the arguments are passed to the parameters of subroutines are defined by the language, but the details of how this is represented in any particular computer system depend on the calling conventions of that system.
See also
- Computer program
- Computer programming
- Computer science
- Input (computing)
- Parameter
- Subroutine
- Variable (computer science)
External links
- Parameter (computer programming) @ Wikipedia