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.
This comparison appears in almost every exam paper.
| Feature | Procedure | Function |
|---|---|---|
| Returns a value? | No | Yes |
| Keyword used to define | PROCEDURE ... ENDPROCEDURE | FUNCTION ... ENDFUNCTION |
Uses RETURNS in header? | No | Yes (RETURNS <data type>) |
CALL.Procedure vs function: what the mark scheme expects
What comes up: "Describe how a function is used in a program" or "Explain the difference between a procedure and a function" (3 marks, max three from four mark points).
Write: State all four steps in the function's lifecycle: (1) the function is invoked by its identifier, using a call statement; (2) arguments may be passed in from the calling program as parameters; (3) the function carries out its task; (4) it then returns a value back to the calling program, where it appears as part of an expression. For a procedure: the same first three steps apply, but a procedure does not return a value and is invoked with the CALL keyword rather than inside an expression.
Watch out: The most commonly dropped mark is omitting that the function returns a value to the calling program. A procedure performs a task and stops there; stating that a procedure "returns a result" is incorrect and will cost the mark for that distinction. Also note: a function is used directly inside an expression (e.g. assigned to a variable or placed in a condition), never with CALL.
RETURN <value>?| Usually no |
| Yes (the value to send back) |
| How it is called | With CALL keyword | Used inside an expression (no CALL) |
| Typical use | Doing something (output, save, update state) | Calculating something and giving the value back |
| Example pseudocode call | CALL CalculateArea(5, 3) | Result ← CalculateArea(5, 3) |