Two results competing for one destination

A stock simulation uses value-result passing. Each parameter receives its own local copy of its argument's integer at entry. Assignments update those local copies. On return, each final local value is copied back to the caller variable supplied for that parameter.


The program makes this call using the following pseudocode, where = means assignment:


Plain text
procedure revise(value-result p, value-result q)
    p = p + 6
    q = 2 * q
    p = p + q
end procedure

revise(stock, stock)


Both arguments designate the same caller variable stock, initially containing 11 units. Consider two independent runs, each starting with 11 units. In one run, the procedure copies back p first and q second. In the other, it copies back q first and p second.


Find the final stock in units for each run. Enter exact integers. Use the specified copy-out order for each run.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Parameter Passing Questions: