"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.

Share:
345,509
Admin
Author by

Admin

Updated on December 10, 2020

Comments

  • Admin
    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
    vol7ron about 11 years
    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.
  • kasperhj
    kasperhj about 9 years
    Or, a method has parameters and takes arguments.
  • Eduardo La Hoz Miranda
    Eduardo La Hoz Miranda about 9 years
    Someday I will explode and it will be a shower of developer's lingo.
  • ngDeveloper
    ngDeveloper almost 9 years
    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?
  • Caltor
    Caltor almost 9 years
    I remember it by saying "for the sake of argument, if we pass in anInt and 2.0". idioms.thefreedictionary.com/for+the+sake+of+argument
  • B T
    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
    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
    B T over 8 years
    @jimbojw I stand partially corrected ; ) Neat
  • T.J. Crowder
    T.J. Crowder over 7 years
    Citation for the above?
  • LegendLength
    LegendLength over 6 years
    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.
  • Phil
    Phil over 5 years
    If you like analogies- Method is like salad bowl. Argument is like greens. Parameter is like salad.
  • Emil
    Emil over 5 years
    For 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
    provisota over 4 years
    Brilliant! This question is torturing me for a long time! :) Thank you so much!
  • rodrigo-silveira
    rodrigo-silveira about 4 years
    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.
  • Quetzalcoatl
    Quetzalcoatl about 4 years
    Somtimes 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
    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 used settings or options instead of args, to not confuse with the language-level arguments.
  • ccpizza
    ccpizza over 2 years
    An 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.