Assignment_1_Solutions (1)

Assignment_1_Solutions (1) - 2-15) The value of M when by:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
2-15) The value of M when by: i) reference is 2 ii) value-result is 3. Explanation: By-reference : X and y are pointing to N at the callee AR. Hence any change of value to either one of them (X or Y) results in an immediate change to the value of N, and consequently to the other formal value. If we change X, N will change and hence Y, and vise versa. X= 1 in SUB TEST changes the value of N at the main and Y at TEST to be 1. Hence, adding X to Y will result in 2 which will be stored in M (pointed to be Z). Hence M will end up having the value 2 . By-value-result: inside TEST, the execution of X=1 does not change N, hence Y remains 2. When we do Z = X + Y we are adding 1 + 2 and will end up having the value 3 upon existing the TEST subroutine. 2-16) i) If the addresses are computed once, on entry at the caller, then the program prints 10 , 20 , 11 . Steps: 1) At the caller side: “Call SUB (I, A(I))” the value of the actual parameters: I is 1 and A(1) = 10 2) at the callee side (inside SUB): The formal actual substitution process will place the value 1 (of
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Assignment_1_Solutions (1) - 2-15) The value of M when by:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online