Concepts / Parameters and Arguments: What's the Difference?

Parameters and Arguments: What's the Difference?

The three key parts of a function call are the function name, the argument or arguments supplied as input data, and the return value produced as the result.

  • Programming

From Call to Result

A function is a named sequence of statements that performs a computation. Calling the function by its name causes those statements to execute. A function call connects the code that asks for the computation, the input data supplied to it, and the result produced afterward.

Key point

The three key parts of a function call are the function name, the argument or arguments supplied as input data, and the return value produced as the result.

Callerrequests a computationArgumentinput dataFunctionnamed statementsReturn valuecomputed resultCalleruses the resultsuppliesentersproducesreturns to
How does a value move from the caller into a function, get used by its statements, and come back as the result?

A Function in Motion

Imagine a generated example with a function named double. Its statements take an input value, multiply that value by two, and produce the result. If the caller supplies 6, the function uses 6 during its computation and sends 12 back. The caller can then display 12, store it, or use it in another computation.

Worked example

Tracing a Generated Function Call

A function named double multiplies its input by two. What result comes back when the caller supplies 6?

  1. 1
    Find the function name

    The function being called is double.

  2. 2
    Find the argument

    The caller supplies 6. That supplied value is the argument.

  3. 3
    Follow the computation

    The function's statements multiply the supplied value by two.

  4. 4
    Identify the return value

    Multiplying 6 by two produces 12, which is the result sent back to the caller.

Result

The return value is 12.

6argument12return valuedoublefunctionentersreturns
How do the supplied argument and the function's statements determine the value returned to the caller?

Parameters Versus Arguments

A parameter is the function's named place for receiving input. An argument is the value or variable supplied by the caller in a particular function call. The parameter belongs to the function's definition; the argument belongs to the call that provides data to the function. In a generated example, a function may use the parameter number, while a caller supplies the argument 6. The parameter and argument correspond during that call, but they are not the same role.

numberfunction input name6supplied input valuesupplies a value for
How does a function's parameter correspond to the argument supplied in a specific function call?
TermWhere it appearsRole
ParameterIn the functionNamed place that receives input
ArgumentIn the function callValue or variable passed into the function
Return valueAfter the function performs its workResult sent back to the caller

The terms describe different parts of the same data flow.

The Call Sequence

To analyze a function call, follow its sequence. First, the caller identifies the function by name. Next, the caller supplies one or more arguments as input data. The function's named statements then perform their computation using that input. Finally, the function produces a return value and sends it back to the caller. The returned value can be displayed, stored, or used in further computations.

Function nameidentifyArgumentssupply inputFunction statementsperform computationReturn valuesend result backthenprovide data toproduce
What happens first when code uses a function name, supplies arguments, executes the function, and receives a return value?
Function calluse the nameReceive inputparameter receives argumentComputerun statementsReturn resultsend value backstartspasses data toproduces
What statements belong inside a function, and how does calling its name cause those statements to run?

Mistakes Beginners Make

  • Common mistake

    Calling the argument a parameter

    What it looks like

    Describing 6 supplied in a particular call as the function's parameter

    Why it fails

    The supplied value is an argument. A parameter is the function's named place for receiving input.

    Do this instead

    Use parameter for the function-side input name and argument for the value or variable supplied by the caller.

  • Common mistake

    Treating the function name as the result

    What it looks like

    Assuming that naming a function tells you what value it produces

    Why it fails

    The function name identifies the named sequence of statements to execute. The return value is the result produced after those statements perform their work.

    Do this instead

    Follow the function's computation and identify the value sent back as the return value.

  • Common mistake

    Stopping after identifying the input

    What it looks like

    Seeing the argument 6 and concluding that the call's result is 6

    Why it fails

    The argument is input data. The function uses it to perform its computation, which may produce a different return value.

    Do this instead

    Trace the statements inside the function before predicting the returned result.

  • Common mistake

    Assuming a return value has no use

    What it looks like

    Ignoring the result after the function finishes

    Why it fails

    A return value is sent back to the caller and can be displayed, stored, or used in further computations.

    Do this instead

    Look for how the caller uses the returned result.

Best practice

When reading an unfamiliar function call, label four things in order: the function name, the supplied argument or arguments, the statements that use the input, and the return value. This prevents the common mistake of treating the input and output as the same thing.

Check Your Understanding

What do you think happens?

A generated function named add_three receives an argument and adds 3 to it. What return value should come back when the caller supplies 4?

  • The function name

  • 4

  • 7

  • The parameter name

Reveal answer
Answer:

7

The supplied value 4 is the argument. The function's statements add 3, so the return value is 7.

EASY

Consider a generated function named triple whose statements multiply its input by three. Identify the function name, the parameter's role, the argument in a call that supplies 5, and the return value.

Hints
  • The function name identifies which named sequence of statements runs.
  • The argument is the value supplied by the caller.
  • Apply the function's stated computation to the supplied value.

Key Takeaways

  1. 1
    A function is a named sequence of statements that performs a computation when called.
  2. 2
    A function call includes a function name, argument or arguments, and a return value.
  3. 3
    A parameter is the function-side name or place for input; an argument is the value or variable supplied by the caller.
  4. 4
    Arguments flow into a function, and the function's computation produces a return value for the caller.
  5. 5
    A returned value can be displayed, stored, or used in further computations.

At a glance

  • A function is a named sequence of statements that performs a computation.
  • The function name identifies what is called, while the argument supplies input data.
  • The parameter is the function's receiving name or place for input; the argument is the supplied value or variable.
  • The function uses its input, performs its statements, and sends a return value back to the caller.
  • To predict a call's result, trace the argument through the function's computation.

Related concepts

More concepts starting with P