We read your photo as:
Differentiate between call by reference and call by value, construct a trace table for calc(8, 37) and state the operation performed by this subroutine.
ScanSolve AI Answer
a) Differentiate between call by reference and call by value
- In call by value, a copy of the argument's value is passed to the subroutine. Any changes made to the parameter inside the subroutine do not affect the original argument.
- In call by reference, a reference (memory address) to the original argument is passed. Changes made to the parameter inside the subroutine directly modify the original argument.
b) Construct the trace table for the subroutine call calc(8, 37)
Given d = 8 and q = 37.
Initial values: r = 0, p = 0.
| Step | q >= d * p (37 >= 8 * p) | p | r |
|---|---|---|---|
| Initial | 0 | 0 | |
| Loop 1 | 37 >= 8 * 0 (True) | 1 | 0 |
| Loop 2 | 37 >= 8 * 1 (True) | 2 | 0 |
| Loop 3 | 37 >= 8 * 2 (True) | 3 | 0 |
| Loop 4 | 37 >= 8 * 3 (True) | 4 | 0 |
| Loop 5 | 37 >= 8 * 4 (True) | 5 | 0 |
| Loop 6 | 37 >= 8 * 5 (False, 37 < 40) | 5 | 0 |
p = p - 1 | 4 | 0 | |
r = q - (d * p) | 4 | 37 - (8 * 4) = 5 | |
| 4 | 5 |
The subroutine will print p = 4 and r = 5.
c) Assuming that the arguments are both positive, state the operation performed by this subroutine
This subroutine performs integer division and calculates the remainder. It finds the quotient (p) and the remainder (r) when q is divided by d.
d) Give a formula that relates p, r, q & d
The relationship between the quotient (), remainder (), dividend (), and divisor () is:
where .
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.
More Computer Science Questions

Handwritten Step-by-Step Solution
Get this as a handwritten image on WhatsApp — like a tutor wrote it for you.
Try on WhatsApp