722

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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 128
    In Russian "parameters" are called "formal parameters", while "arguments" are called "actual parameters". – Dims Jun 11 '13 at 10:38
  • 10
    We use this convention italian as well. – Dacav Dec 04 '13 at 13:29
  • 215
    I like this quote from [MSDN](http://msdn.microsoft.com/en-us/library/9kewt1b3.aspx): "...the procedure defines a parameter, and the calling code passes an argument to that parameter. You can think of the ***p**arameter* as a ***p**arking space* and the ***a**rgument* as an ***a**utomobile*." – Michiel van Oosterhout Dec 16 '14 at 21:24
  • 2
    argument is the one you use it, while parameter is a blank to be filled in. –  Sep 22 '17 at 09:14
  • 1
    We pass argument(s) while calling a function and the function receives as parameter(s). – Forhad Hossain Jul 07 '21 at 00:23

1 Answers1

1227

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.

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
tranmq
  • 15,168
  • 3
  • 31
  • 27
  • 221
    Old 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. – vol7ron May 08 '13 at 15:47
  • 103
    Or, a method has parameters and takes arguments. – kasperhj May 29 '15 at 07:07
  • 35
    Someday I will explode and it will be a shower of developer's lingo. – Eduardo La Hoz Miranda Jun 10 '15 at 20:28
  • 8
    Why 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? – ngDeveloper Jul 28 '15 at 19:04
  • 2
    I remember it by saying "for the sake of argument, if we pass in `anInt` and `2.0`". http://idioms.thefreedictionary.com/for+the+sake+of+argument – Caltor Aug 10 '15 at 10:02
  • 24
    @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. – B T Nov 09 '15 at 02:10
  • 7
    @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"]`. – jimbo Feb 05 '16 at 10:39
  • @jimbojw I stand partially corrected ; ) Neat – B T Feb 11 '16 at 06:55
  • Citation for the above? – T.J. Crowder Oct 13 '16 at 21:45
  • 1
    I 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. – LegendLength Oct 13 '17 at 06:57
  • If you like analogies- Method is like salad bowl. Argument is like greens. Parameter is like salad. – Phil Oct 05 '18 at 21:10
  • 2
    For a non-technical perspective, the general definition of parameter (beyond programming), according to [Cambridge Dictionary](https://dictionary.cambridge.org/us/dictionary/english/parameter) 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. – Emil Feb 06 '19 at 18:51
  • Brilliant! This question is torturing me for a long time! :) Thank you so much! – provisota Oct 26 '19 at 15:18
  • Yet 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. – rodrigo-silveira Apr 09 '20 at 04:47
  • Somtimes google doc string suggestions [http://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? – Quetzalcoatl Jun 17 '20 at 20:59
  • @Quetzalcoatl: I see they [imported code from Copybara](https://github.com/google/styleguide/commit/cfce3c3a); 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 used `settings` or `options` instead of `args`, to not confuse with the language-level arguments. – Kamafeather Sep 10 '20 at 18:23
  • An easy way to remember: [`ARGV`](https://en.wikipedia.org/wiki/Command-line_argument_parsing) 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. – ccpizza Mar 17 '22 at 20:45