is there a difference between a parameter and an argument, or are they simply synonyms?
Argument is often used in the sense of "actual argument" vs. "formal parameter".
The formal parameter is what's given in the function declaration/definition/prototype, the actual argument is what's passed when calling the function, an instance of a formal parameter, if you will.
That being said, they're often used interchangably, or depending on language/community, and I've also heard "actual parameter" &c.
So here, x
and y
would be formal parameters:
int foo(int x, int y) {
...
}
Whereas here, in the function call, 5 and z
are the actual arguments:
foo(5, z);
Generally, the parameters are what are used inside the function and the arguments are the values passed when the function is called. Unless you take the opposite view.
double sqrt(double x)
{
...
return x;
}
void other(void)
{
double two = sqrt(2.0);
}
Under my thesis, x is the parameter to sqrt()
and 2.0 is the argument.
The terms are often used at least somewhat interchangeably.
They are often used interchangeably in text, but in most standards the distinction is that an argument is an expression passed to a function, where a parameter is a reference declared in a function declaration.
Depends on what is the context of the question. If this is about C++ standard, yes they have different definitions in the standard.