Parameters vs Arguments
Parameters and arguments are both function inputs, but they have different meanings:
- Parameters are the placeholders you declare in the function definition.
- Arguments are the actual values you pass in the function call.
Definition vs Call
In the Function definition, parameters are the variables:
// dividend and divisor are parameters
static double Division(double dividend, double divisor)
{
return dividend / divisor;
}
In the Function call, arguments are the values passed to the function:
double numberA = 2.0;
double numberB = 3.0;
// numberA and numberB are arguments
double result = Division(numberA, numberB);
Argument Order Matters
Arguments are matched to parameters by position, so swapping them changes the result:
double result1 = Division(1, 2); // 0.5
double result2 = Division(2, 1); // 2.0
The number of arguments must also match the number of parameters:
Division(1, 2, 3); // ❌ Error: no overload takes 3 arguments
Division(1); // ❌ Error: missing argument for 'divisor'
To accept three inputs, the function must declare three parameters.
Summary
- Argument names don't need to match parameter names. Arguments don't even need names,
Division(2.0, 3.0)works fine - Parameters exist only inside the function
- Each argument must match its parameter's type, or be convertible to it