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 parameters.
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 CALL CalculateArea(5, 3):
Length and Width are the parameters.5 and 3 are the arguments.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.