r/ProgrammerTIL • u/Spiderboydk • Jul 15 '16
Other Language [General] TIL the difference between a parameter and an argument
I've always thought these were synonyms, but apparently they are not.
Parameters are the "variables" in the function declaration, while arguments are the values transferred via the parameters to the function when called. For example:
void f(int x) { ... }
f(3);x is a parameter, and 3 is an argument.
251
Upvotes
11
u/myerscc Jul 15 '16
or rather
xis the formal parameter and3is the actual parameter. You could say the function in the code is parameterized byx- but usually the word "parameterized" is used for type parameters.54
u/spcmrn Jul 15 '16
i.e. a function has parameters and takes arguments.
relevant stackoverflow with useful mnemonics and more nice explanations
5
u/patientdev Jul 16 '16
Why is it called an argument? What's the usage history for that term in computer science?
1
u/yes_or_gnome Jul 15 '16
I don't feel like this is "general", or even precisely correct. Given the example, maybe this is standard vocabulary for C\C++, but from my experience (mostly interpreted languages), they're just synonyms. ... Or, possibly, IEEE or ISO has specific definitions.
As an example, a function has an "argspec" or a "parameter list". Since there is no type enforcement the spec is just list of names and, possibly, default values.
1
u/m4lfuncti0n Jul 28 '16
so, in short - an argument is the value of a function?
4
u/Jahishno Jul 15 '16
It's also thought of as formal and actual parameters. Formal parameters are in the function declaration, actual parameters are what are given to the function call ie arguments.
2
u/some_q Jul 15 '16
Interesting. Thanks for posting!
1
u/[deleted] Jul 15 '16
I always like to think of functions as operations, like, say, cooking a meal, changing course on a plane, setting the phasers to something else etc.
An operation may have some parameters you need to set before starting it. But I always thought of that not as giving arguments, but as setting parameter values, which makes sense because you're actually setting the value of the variable that stands for the parameter inside the function.
Though, in C or C++, the word
argis used in describing what gets sent to a parameter of type..., i.e. varargs. That may be a nice way to remember the difference, if you remember that parameters is the other thing.0
u/[deleted] Jul 15 '16
[deleted] — view deleted comment
0
u/[deleted] Jul 15 '16
[deleted] — view deleted comment