Question 1
2 marksHere is part of a program.
function calc(a, b)
result = a * 2 + b
return result
endfunction
x = calc(3, 4)
y = calc(x, 1)
print(y)State the value of x and the output of the program.
Model answer
x = 10
Output: 21
Explanation
calc(3, 4) works out 3 * 2 + 4 = 10 and returns it, so x = 10. The second call passes x as a, so it works out 10 * 2 + 1 = 21, which is stored in y and output. Multiplication is done before addition, so 3 * 2 + 4 is 10, not 14.
Mark scheme
-
1 mark
x = 10
-
1 mark
21
follow through: 2 × the student's x + 1