A valid use of a function
A function has this header:
FUNCTION Larger(A : INTEGER, B : INTEGER) RETURNS INTEGER
Which statement is a valid use of the function?
A CALL Larger(3, 9)
B Larger(3, 9) ← Result
C Result ← Larger(3, 9) * 2
D Result ← CALL Larger(3, 9)
[1]
- 1
A function is used in an expression: its return value replaces the call.
CALLis only for procedures, so A and D are wrong. B tries to assign a value to the call, which is not possible. - 2
In C the call
Larger(3, 9)is replaced by its return value, 9, soResultbecomes 18. Answer C (1).
Answer
C
Examiner tip
Examiner tip: read a function call as 'the value it returns'. Anywhere you could write a value of the return type, you can write the call.
Common mistake: choosing A. A function called with CALL would throw its return value away; Cambridge pseudocode uses CALL only with procedures.