Question 1
2 marksDescribe the difference between a procedure and a function.
Model answer
A function always returns a single value to the place it was called from, so it is used inside an expression, for example Area ← CalculateArea(4.0, 2.5). A procedure carries out a task but does not return a value, and it is run with a CALL statement, for example CALL ShowMenu.
Explanation
Both are named blocks of code that can be called many times. The key difference is the returned value: a function header ends with RETURNS and a data type, and its body uses RETURN. A common mistake is to say 'a function has parameters and a procedure does not' - both can have parameters, or none.
Mark scheme
-
1 mark
A function returns a (single) value to the statement that called it
max 2
-
1 mark
A procedure does not return a value / a procedure just carries out a task
-
1 mark
A function is called as part of an expression or assignment (e.g. Result ← Square(5)) whereas a procedure is called using CALL