Question 1 Report
Study the following pseudocode.
FUNCTION Double(N : INTEGER) RETURNS INTEGER
RETURN N * 2
ENDFUNCTION
FUNCTION AddThree(N : INTEGER) RETURNS INTEGER
RETURN N + 3
ENDFUNCTION
DECLARE A : INTEGER
DECLARE B : INTEGER
A ← 4
B ← Double(A)
A ← AddThree(B)
B ← Double(AddThree(A))
OUTPUT A, " ", B(a) State the output. [1]
(a) This question tests the ability to trace through nested function calls. [1]
Step-by-step evaluation:
A ← 4B ← Double(4): the function returns 4 * 2 = 8, so B = 8A ← AddThree(8): the function returns 8 + 3 = 11, so A = 11B ← Double(AddThree(11)): first evaluate the inner call, AddThree(11) = 14; then Double(14) = 28, so B = 28OUTPUT: 11 28 [1]
Everything you need to excel in your exams