0984

Procedures and Functions

Programming · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 4% of your exam marks.

stable
Rare
Stable4%

Writing and calling procedures/functions with parameters is tested in Paper 2.

This comparison appears in almost every exam paper.

FeatureProcedureFunction
Returns a value?NoYes
Keyword used to definePROCEDURE ... ENDPROCEDUREFUNCTION ... ENDFUNCTION
Uses RETURNS in header?NoYes (RETURNS <data type>)
Contains RETURN <value>?Usually noYes (the value to send back)
How it is calledWith CALL keywordUsed inside an expression (no CALL)
Typical useDoing something (output, save, update state)Calculating something and giving the value back
Example pseudocode callCALL CalculateArea(5, 3)Result ← CalculateArea(5, 3)

Quick rule of thumb

  • If the sub-program's job is to DO something, write a procedure and call it with CALL.
  • If the sub-program's job is to PRODUCE a value, write a function and use it inside an expression.
Exam tip

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.