SDD8 — Parameter Passing
- I can define formal parameter and actual parameter, and identify each in a piece of code
- I can explain how actual parameters are matched to formal parameters by position
- I can trace code and predict the effect of calling a sub-program with actual parameters in the wrong order
- I can point to the exact line of code where a formal parameter is declared, and the exact line where an actual parameter is supplied
- I can explain, using an example, why actual parameters are matched to formal parameters by position rather than by name
- I can predict the (incorrect) result of a sub-program call where the actual parameters have been swapped
return statement anywhere inside it?Key vocabulary
Matching values to a sub-program's inputs
What is a formal parameter?
A formal parameter is the name written inside a sub-program's own definition to represent one of its inputs. In def isAffordable(price, budget):, both price and budget are formal parameters — they are placeholders, existing only to describe what kind of input the function expects and how that input will be referred to inside the function's own code. A formal parameter has no value of its own until the sub-program is actually called.
What is an actual parameter?
An actual parameter is the real value or variable supplied at the point where a sub-program is called. In the call isAffordable(75, 100), 75 and 100 are actual parameters — real data being handed into the function for this particular call. An actual parameter does not have to be a literal value like 75; it can equally be a variable, such as isAffordable(itemPrice, budgetLimit), or even an expression, such as an element of a record like itemRecords[2]. Whatever form it takes, its role is the same: supplying one real input for this specific call.
How actual parameters are matched to formal parameters
Actual parameters are matched to formal parameters by position, not by name. The first actual parameter in a call is matched to the first formal parameter in the definition, the second actual parameter to the second formal parameter, and so on. This is exactly why calling isAffordable(75, 100) sets price to 75 and budget to 100 — not because the names "match" in any way, but purely because of the order in which the values appear. The formal parameter's name and the actual parameter's name (if it has one, as with a variable) never need to be the same, and usually are not.
Why this matters when tracing code
Because matching is entirely positional, swapping the order of two actual parameters in a call silently changes what each formal parameter receives, without causing any error — the code still runs, it just runs on the wrong data. This makes parameter order a genuine source of quietly incorrect programs, and a common focus for exam questions that ask you to trace through a call and state what a sub-program actually receives and returns.
This links back directly to SDD7's idea of modular design. A function or procedure is only reliable as a reusable building block if every call site supplies its actual parameters in the correct order — the sub-program itself has no way of checking whether the values it receives make sense for the names it was given, since by the time it runs, the formal parameters are simply bound to whatever values arrived in whatever order they arrived. Careful, consistent ordering at every call site is therefore part of writing dependable modular code, not a minor detail.
Formal and actual parameters, side by side
In isAffordable(75, 100) calling def isAffordable(price, budget): — the first actual parameter (75) is matched to the first formal parameter (price), and the second actual parameter (100) to the second formal parameter (budget), purely by position.
Worked examples
def isAffordable(price, budget):
return price <= budget
isAffordable(75, 100)def line declares two formal parameters: price and budget. The call supplies two actual parameters: 75 and 100.price receives 75 and budget receives 100. 75 <= 100 is True, so the call returns True.itemPrice = 90 budgetLimit = 80 isAffordable(itemPrice, budgetLimit)
itemPrice and budgetLimit, not literal numbers. Positional matching still applies exactly the same way: whatever value itemPrice holds is matched to the formal parameter price, and whatever value budgetLimit holds is matched to budget.price receives 90, budget receives 80. 90 <= 80 is False, so the call returns False — notice the variable names itemPrice/budgetLimit never need to match the formal parameter names price/budget.def isInStock(record):
return record.stock > 0
isInStock(itemRecords[2])
where itemRecords[2] = Item("Chocolate", 75, 30).record. The single actual parameter is the expression itemRecords[2], which evaluates to the whole Chocolate record before being passed in.record.stock is 30, and 30 > 0 is True — the call returns True.def calculateChange(amountPaid, price):
return amountPaid - price
calculateChange(100, 75)
Identify: the formal parameters, the actual parameters, and the value this call returns.
- Mixing up "formal" and "actual". The formal parameter is the name in the definition; the actual parameter is the real value supplied at the call — pupils frequently get these the wrong way round.
- Assuming parameters are matched by name. Matching is by position — a formal parameter called
pricehas no special connection to a variable calledpriceused as an actual parameter elsewhere. - Believing only variables can be actual parameters. Literal values (like
75) and expressions (likeitemRecords[2]) are equally valid actual parameters. - Not spotting a swapped-order call. Calling a sub-program with actual parameters in the wrong order produces a result that runs without error, but is quietly wrong.
- Confusing this with SDD9's topic. Whether a formal parameter's name can be accessed elsewhere in the program is a question of scope, covered next in SDD9, not parameter passing itself.
When asked to identify a formal or actual parameter in a piece of code, point to the exact line: formal parameters are named in the def line; actual parameters appear in the call. Naming the correct term without locating it in the right line rarely earns full marks — examiners expect the distinction to be tied to specific code, not just defined in the abstract.
Task Set A — Core questions
def isAffordable(price, budget):
return price <= budget
isAffordable(75, 100)
Which of these is a formal parameter in this code?isAffordable(75, 100)?def isAffordable(price, budget):, calling isAffordable(90, 80) matches the actual parameter 90 to which formal parameter?def isInStock(record): return record.stock > 0, and calling isInStock(itemRecords[2]) where itemRecords[2] = Item("Chocolate", 75, 30), what does the call return?calculateChange with two formal parameters, amountPaid and price, that returns the change due (amountPaid minus price). Then write a call to this function using the actual parameters 100 and 75.def calculateChange(amountPaid, price):
return amountPaid - price
calculateChange(100, 75)
calculateChange as your example. (3 marks)calculateChange(75, 100) instead of calculateChange(100, 75), and explain why this is a risk specific to positional matching. (3 marks)Task Set B — Extension
price inside isAffordable, is not accessible anywhere outside that function.isAffordable(budget=100, price=75), where the order no longer matters. Suggest one advantage of this over strictly positional matching, and one reason it isn't the primary method emphasised at this level.Higher Computing Science → Software Design & Development → SDD8
Single period — this is a focused, narrower topic than SDD5–7, building directly on SDD7's functions/procedures rather than introducing a new scenario.
Suggested timing: 5 min warm-up + vocab · 15 min notes + param-map visual (live-code example 1 and print() the values inside the function to prove the matching) · 10 min examples 2–3 · 5 min "now you try" · 25 min Task Set A · Task Set B as homework.
Key misconception: pupils often think the formal and actual parameter must share the same name to "work" — deliberately demonstrate example 2 (itemPrice/budgetLimit matching price/budget) live to break this assumption early.
SQA command words covered: describe, explain, identify, trace, predict.
Extension suggestion: Extension 1 sets up SDD9 directly — if time is tight, this can be skipped from class discussion and picked up again as the SDD9 warm-up instead.
Implementation note (5 Jul 2026): Example 3 and Task Set A Question 7 were switched from dictionary-based records to @dataclass-based records after the fact, to match SDD6/SDD7's updated implementation (see SDD6 teacher notes for the full rationale). isInStock now reads record.stock rather than record["stock"].