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
andy
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);
Jake Petroules : Speaking of terminology, what is the "&c" you used? Does that mean "and vice versa" or something like that?danlei : "&" is a ligature of "e" and "t", so it means "et", which is latin for "and". The "c" stands for "cetera", which means "(the) other(s)" (Nom. pl. n.). So you can substitute it with something like "and (the) other things", or "and so on". -
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.
0 comments:
Post a Comment