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?