In computing, a parameter is a type of variable that is received by a function, procedure, or subroutine. From English: parameter.
A parameter influences the behavior or the result of the execution of the function, procedure or subroutine (hereinafter just procedure) that receives it. They are widely used in programming.
In general, in a procedure definition, an ordered list of parameters is included; in this way, each time the procedure is called, the arguments of that call can be assigned to the corresponding parameters. The technical difference between parameter and Argument is subtly explained here, although they are often treated as synonyms.
The semantics of how parameters can be declared and how arguments are passed to procedure parameters are defined by each programming language.
Ways to pass a parameter
In general, there are two ways to pass a parameter to a procedure: by value and by reference.
A parameter is passed by value when its content is copied and if its value is altered within the procedure, the original parameter is not modified. On the other hand, when a parameter is passed by reference, if its value is modified within the procedure, the original value is modified outside of it.
Type of data
In strongly typed programming languages, each parameter type must be explicitly specified in the procedure declaration. Whereas languages that use type inference try to automatically discover the types of the function body and its usage. In weakly typed programming languages, the type of the parameter is resolved at run time.
Some languages use a special keyword (for example, void) to indicate that the procedure has no parameters.
Parameter example
add(int a, int b) {
return a + b;
}
int a = 2;
int b = 3;
result = add(a, b);
show(result);
In this pseudocode example, the function named add is defined, with two input parameters, two integers a and b, which are added together. The result in this particular case is 5.
Difference between parameter and argument in programming
In general, the words argument and parameter are taken as synonyms; actually there is a difference: the parameters appear in the procedure definition, the arguments appear in the procedure calls.
A parameter is an intrinsic property of a procedure, since it is included in its definition. Instead, the arguments are more like the current values assigned to the variable parameters when the subroutine is called. In practice, there is usually no clear distinction between the two terms.
For more information and examples see: Difference between parameter and argument in programming
Doubts? needs more information? Write and we will respond to your email: click here