"Parameter" vs "Argument"
345,509
A parameter is the variable which is part of the method’s signature (method declaration). An argument is an expression used when calling the method.
Consider the following code:
void Foo(int i, float f)
{
// Do things
}
void Bar()
{
int anInt = 1;
Foo(anInt, 2.0);
}
Here i
and f
are the parameters, and anInt
and 2.0
are the arguments.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on December 10, 2020Comments
-
Admin over 3 years
I got parameter and argument kind of mixed up and did not really pay attention to when to use one and when to use the other.
Can you please tell me?
-
vol7ron about 11 yearsOld post, but another way of saying it:
argument
is the value/variable/reference being passed in,parameter
is the receiving variable used w/in the function/block. -
kasperhj about 9 yearsOr, a method has parameters and takes arguments.
-
Eduardo La Hoz Miranda about 9 yearsSomeday I will explode and it will be a shower of developer's lingo.
-
ngDeveloper almost 9 yearsWhy is it that within JavaScript, when you want to access the parameters of a function/method, you have to access the "arguments" variable? Shouldn't that be "parameters" instead?
-
Caltor almost 9 yearsI remember it by saying "for the sake of argument, if we pass in
anInt
and2.0
". idioms.thefreedictionary.com/for+the+sake+of+argument -
B T over 8 years@ngDeveloper Nope, it should be arguments. You get access to the list of argument values passed to the function. Consequently you don't get a list of the parameter names of the function, javascript doesn't give you a way to get that info.
-
jimbo over 8 years@BT You're correct that it should be arguments, but JS does give you a way to get the parameters. When you cast a function as a string, the names of parameters are in-tact if you parse them out. E.g.
function foo(a, b) {}
then(foo+'').split(/\W+/).slice(2,-1)
produces["a", "b"]
. -
B T over 8 years@jimbojw I stand partially corrected ; ) Neat
-
T.J. Crowder over 7 yearsCitation for the above?
-
LegendLength over 6 yearsI feel like this is a case where the definitions should just be collapsed into 1. There's rarely a need to differentiate between the two concepts and if you really need to just label them 'internal' or 'external' parameters or something similar.
-
Phil over 5 yearsIf you like analogies- Method is like salad bowl. Argument is like greens. Parameter is like salad.
-
Emil over 5 yearsFor a non-technical perspective, the general definition of parameter (beyond programming), according to Cambridge Dictionary is
a set of facts which describes and puts limits on how something should happen or be done
. If you internalize this, then you'll remember that a method is bound/defined by parameters. -
provisota over 4 yearsBrilliant! This question is torturing me for a long time! :) Thank you so much!
-
rodrigo-silveira about 4 yearsYet another way to think of this: when you have code with hard-coded values, you can make it more generic by "parameterizing" it. That is, make it into a function with "parameters" that represent any arbitrary input.
-
Quetzalcoatl about 4 yearsSomtimes google doc string suggestions [google.github.io/styleguide/pyguide.html] has "Args" as what we formally define as "parameters" -- is it common to use "Params" instead of "Args" to document the arguments that a method receives?
-
Kamafeather almost 4 years@Quetzalcoatl: I see they imported code from Copybara; in there
args
is often modelled as a iterable object; so it is not intended just in the usual meaning (aka: construct at programming-language level). Many methods in the project specify a Parameter called args, defined as an array of values (these are not defines as parameters, but they are just runtime values). So I think the docs author probably got confused. I would have usedsettings
oroptions
instead ofargs
, to not confuse with the language-level arguments. -
ccpizza over 2 yearsAn easy way to remember:
ARGV
has been around since forever and has propagated from C/C++ to other languages like python, perl, ruby, js, etc, and stands for the array of values passed via the command line.