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.
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.
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.
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.
Tracing a Generated Function Call
A function named double multiplies its input by two. What result comes back when the caller supplies 6?
- 1Find the function name
The function being called is double.
- 2Find the argument
The caller supplies 6. That supplied value is the argument.
- 3Follow the computation
The function's statements multiply the supplied value by two.
- 4Identify the return value
Multiplying 6 by two produces 12, which is the result sent back to the caller.
The return value is 12.
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.
| Term | Where it appears | Role |
|---|---|---|
| Parameter | In the function | Named place that receives input |
| Argument | In the function call | Value or variable passed into the function |
| Return value | After the function performs its work | Result 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.
Mistakes Beginners Make
Common mistake Calling the argument a parameter
What it looks likeDescribing 6 supplied in a particular call as the function's parameter
Why it failsThe supplied value is an argument. A parameter is the function's named place for receiving input.
Do this insteadUse 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 likeAssuming that naming a function tells you what value it produces
Why it failsThe 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 insteadFollow the function's computation and identify the value sent back as the return value.
Common mistake Stopping after identifying the input
What it looks likeSeeing the argument 6 and concluding that the call's result is 6
Why it failsThe argument is input data. The function uses it to perform its computation, which may produce a different return value.
Do this insteadTrace the statements inside the function before predicting the returned result.
Common mistake Assuming a return value has no use
What it looks likeIgnoring the result after the function finishes
Why it failsA return value is sent back to the caller and can be displayed, stored, or used in further computations.
Do this insteadLook for how the caller uses the returned result.
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?
Reveal answer
7
The supplied value 4 is the argument. The function's statements add 3, so the return value is 7.
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
- 1A function is a named sequence of statements that performs a computation when called.
- 2A function call includes a function name, argument or arguments, and a return value.
- 3A parameter is the function-side name or place for input; an argument is the value or variable supplied by the caller.
- 4Arguments flow into a function, and the function's computation produces a return value for the caller.
- 5A 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.