Difference between an argument and a parameter

The terms parameter and argument are used interchangeably by vast majority of programmers but they both have different meanings. In this post, we will see the difference between an argument and a parameter.

Although parameters are commonly referred to as arguments, but both are very different. According to wikipedia, a parameter is a special kind of variable, used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are the values of the arguments with which the subroutine is going to be called/invoked.

In simpler terms, the argument the actual value that is supplied to a function whereas the parameter is the variable inside the definition of the function. We can say that a parameter is a type that appear in function definitions, while an argument is an instance that appear in function calls.

For example, consider the following function definition:

int add (int x, int y) {
return x + y;
}

The add() function takes two parameters x and y. If the function is called as add(2, 3), then 2, 3 are the arguments.

It is worth noting that variables can be arguments. If the function is called as shown below, then the variables a and b are both arguments to the add() function, and not the values 2, 3.

int a = 3;
int b = 2;
add (a,b);

Important Points:

  1. A parameter is also called as formal parameter or formal argument and an argument is often called as actual arguments or actual parameters.
  2. A parameter is optional in some programming langauges and some programming languages allows for a default argument to be provided in a function’s declaration. This means that while calling the function, the caller can omit that argument.
  3. A parameter has a name, a data type, and calling mechanism (call by reference, or call by value), whereas an argument is an expression which do not have any name, but it can be a variable, a constant, or a literal.
  4. The scope of a parameter is the function itself and it serves as a local variable inside the function.
  5. The number of arguments in a function call should match with the number of parameters in the function definition. One exception to this rule is functions with variable-length parameter lists.
  6. The data type of arguments in a function call should match with the data type of parameters in the function definition.
  7. If a parameter is passed by value, modifying it inside the function does not change the corresponding argument in the caller. However, if it is passed by reference, the values of corresponding argument can be chnaged in the caller.