192
votes

I often find myself confused with how the terms 'arguments' and 'parameters' are used. They seem to be used interchangeably in the programming world.

What's the correct convention for their use?

12
For the record, a closely related question: stackoverflow.com/questions/156767/… (That's formulated to be C# specific, while this is language-agnostic; basically the same otherwise.)Jonik
@Jonik: It's not really specific to C# since the poster also asked about the terms in other programming languages. The other question is older and (in my opinion) has some better answers.Mechanical snail
And if we view it as language-agnostic, then it really is an exact dupe.Mechanical snail

12 Answers

210
votes

Parameters are the things defined by functions as input, arguments are the things passed as parameters.

void foo(int bar) { ... }

foo(baz);

In this example, bar is a parameter for foo. baz is an argument passed to foo.

202
votes

A Parameter is a variable in the declaration of a function:

functionName(parameter) {
    // do something
}


An Argument is the actual value of this variable that gets passed to the function:

functionName(argument);
28
votes

For user1515422, a very concrete example showing the difference between parameters and arguments:

Consider this function:

int divide(int numerator, int denominator) {
    return numerator/denominator;
}

It has two parameters: numerator and denominator, set when it's defined. Once defined, the parameters of a function are fixed and won't change.

Now consider an invocation of that function:

int result = divide(8, 4);

In this case, 8 and 4 are the arguments passed to the function. The numerator parameter is set to the value of the argument 8, and denominator is set to 4. Then the function is evaluated with the parameters set to the value of the arguments. You can think of the process as equivalent to:

int divide() {
    int numerator = 8;
    int denominator = 4;
    return numerator/denominator;
}

The difference between a parameter and an argument is akin to the difference between a variable and its value. If I write int x = 5;, the variable is x and the value is 5. Confusion can arise because it's natural to say things like "x is five," as shorthand for "The variable x has the value 5," but hopefully the distinction is clear.

Does that clarify things?

14
votes

Arguments are what you have when you're invoking a subroutine. Parameters are what you are accessing inside the subroutine.

argle(foo, bar);

foo and bar are arguments.

public static void main(final String[] args) {
    args.length;
}

args is a parameter.

6
votes

There is nice section in parameter Wikipedia article about this subject.

In short -- parameter is the formal name defined by function and argument is actual value (like 5) or thing (like variable) passed into function.

4
votes

Although Wikipedia is hardly an authoritative source, it does a decent job of explaining the terms.

I guess you could say that parameters are to arguments what classes are to instances of objects...

2
votes

When you define a function like:

MyFunction(param1,param2) {
  print parameter1, parameter
}

You set the parameters when you define the function. When you call the function like this:

MyFunction('argument1', 'argument2');

You set the values of the parameters to the arguments you passed. The arguments are what you put in the question when you call it. Hope that helped.

1
votes

Simply there is no major differences. If we go deeply inside this we can identify the diff.Mainly we know that Argument/Parameter/signature all are same.

Basically Parameter defines the type of Data we are passing.Where as the Argument defines the actual data/variable we are passing.

Parameter Example :-

int add(int a,int b){ //Here a and be both can treated as Parameter
 return a+b;
}

Argument Example :-

int return_result=add(3,4); // Here 3 and 4 both can treated as Argument

or

int x=3,y=4;
int return_result=add(x,y);// Here x and y both can treated as Argument
1
votes

In most cases, a procedure needs some information about the circumstances in which it has been called. A procedure that performs repeated or shared tasks uses different information for each call. This information consists of variables, constants, and expressions that you pass to the procedure when you call it.

To communicate this information to the procedure, the procedure defines a parameter, and the calling code passes an argument to that parameter. You can think of the parameter as a parking place and the argument as an automobile. Just as different automobiles can park in the parking place at different times, the calling code can pass a different argument to the same parameter each time it calls the procedure.

Parameters

A parameter represents a value that the procedure expects you to pass when you call it. The procedure's declaration defines its parameters.

When you define a Function or Sub procedure, you specify a parameter list in parentheses immediately following the procedure name. For each parameter, you specify a name, a data type, and a passing mechanism (ByVal or ByRef). You can also indicate that a parameter is optional, meaning the calling code does not have to pass a value for it.

The name of each parameter serves as a local variable within the procedure. You use the parameter name the same way you use any other variable.

Arguments

An argument represents the value you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure.

When you call a Function or Sub procedure, you include an argument list in parentheses immediately following the procedure name. Each argument corresponds to the parameter in the same position in the list.

In contrast to parameter definition, arguments do not have names. Each argument is an expression, which can contain zero or more variables, constants, and literals. The data type of the evaluated expression should normally match the data type defined for the corresponding parameter, and in any case it must be convertible to the parameter type.

0
votes

In fact both parameter and argument are different types of parameters. Those are

1)Formal Parameters - variables appear in function/subroutine definitions

for eg. (in Java)

public void foo(Integer integer, String... s2)

Here both integer and s2 are formal parameters or loosely speaking parameters.

2)Actual parameters or arguments - variables appear in subroutines while calling the

already defined subroutine

for eg. (in Java) suppose If the function "foo" resides in object "testObject" ,

testObject.foo(new Integer(1), "test")

So variables in the function definition are called formal parameters or simply parameters and variables while calling methods are called as actual parameters or arguments. I hope it helps.

0
votes

Think of it like basic algebra. X is the parameter that you have to fill in, and the number you place inside of it is the argument. So if you have an equation like X+2, X is your parameter, and any numbers you change for X become known as the arguments. So if using that equation you supplement 1 for x, you get 1+2. That means that 1 is an argument, supplied to the parameter of X.

Equally, if you have a function like dosomething("This"), it's definition would be dosomething(string parametername), but "This" would be the actual argument that is being supplied to the parameter, here named parametername.

In the simplest way to look at it, the parameter is the thing that the argument fills in, and the argument can be any number of things allowed by that parameter.

So it's a many-to-one relationship between Parameters and arguments, as you can have one parameter that can have many valid arguments, like our X+1 equation above. X can be any number known, and they are all valid.

0
votes

A variable is a storage location and an associated symbolic name (an identifier) which contains data, a value.

A parameter is a variable passed to a function.

An argument is data (a value) passed to a function.

$variable = 'data/value';

function first($variable){ ... }

function second('data/value'){ ... }
function third(16){ ... }

In function first we are passing a parameter.

In function second and third we are passing arguments.