Arguments or parameters? [duplicate]
Parameters are the things defined by functions as input, arguments are the things passed as parameters.
void foo(int bar) { ... }
foo(baz);
In this example, bar
is a parameter for foo
. baz
is an argument passed to foo
.
A Parameter is a variable in the declaration of a function:
functionName(parameter) {
// do something
}
An Argument is the actual value of this variable that gets passed to the function:
functionName(argument);
For user1515422, a very concrete example showing the difference between parameters and arguments:
Consider this function:
int divide(int numerator, int denominator) {
return numerator/denominator;
}
It has two parameters: numerator
and denominator
, set when it's defined. Once defined, the parameters of a function are fixed and won't change.
Now consider an invocation of that function:
int result = divide(8, 4);
In this case, 8
and 4
are the arguments passed to the function. The numerator
parameter is set to the value of the argument 8
, and denominator
is set to 4
. Then the function is evaluated with the parameters set to the value of the arguments. You can think of the process as equivalent to:
int divide() {
int numerator = 8;
int denominator = 4;
return numerator/denominator;
}
The difference between a parameter and an argument is akin to the difference between a variable and its value. If I write int x = 5;
, the variable is x
and the value is 5
. Confusion can arise because it's natural to say things like "x is five," as shorthand for "The variable x has the value 5," but hopefully the distinction is clear.
Does that clarify things?
Arguments are what you have when you're invoking a subroutine. Parameters are what you are accessing inside the subroutine.
argle(foo, bar);
foo
and bar
are arguments.
public static void main(final String[] args) {
args.length;
}
args
is a parameter.
There is nice section in parameter Wikipedia article about this subject.
In short -- parameter is the formal name defined by function and argument is actual value (like 5) or thing (like variable) passed into function.