Programming · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 4% of your exam marks.
Writing and calling procedures/functions with parameters is tested in Paper 2.
Both procedures and functions can take .
A parameter is a variable named in the definition of the sub-program; it holds the value passed in by the caller.
An argument is the actual value supplied at the call site.
In CalculateArea(5, 3):
Length and Width are the parameters.5 and 3 are the .PROCEDURE Greet(Name : STRING, Age : INTEGER)
OUTPUT "Hello, ", Name, ", you are ", Age, " years old"
ENDPROCEDURE
CALL Greet("Alice", 17)
The order of arguments must match the order of parameters:
FUNCTION Subtract(X : INTEGER, Y : INTEGER) RETURNS INTEGER
RETURN X - Y
ENDFUNCTION
OUTPUT Subtract(10, 3) // 10 - 3 = 7
OUTPUT Subtract(3, 10) // 3 - 10 = -7 (different result!)
Parameters make sub-programs reusable with different inputs. Without parameters, a procedure that calculated the area of a rectangle would only ever work for one specific length and width. With parameters, the same procedure works for any length and any width the caller chooses.
Why parameters exist
What comes up: "Explain the purpose of parameters in a sub-program" (typically 2–3 marks).
Write (three marks): (1) Parameters allow values to be passed from the calling program into the sub-program. (2) Those values are then available for the sub-program to use as it carries out its statements. (3) Because the values can differ at each call, the same sub-program can be reused with different data without rewriting it.
Watch out: Writing only "parameters pass data in" earns at most one mark. The credited chain requires you to state that the values are used inside the sub-program and that this lets the sub-program be reused with different data on each call.