Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A.x = 5</p> <p>A.y = 7</p> <p>B.x = 3</p> <p>Calls P(3, 7, Q) - Inside P, y is a ref to B.x, which value is 3, z is 7. Due to dynamic scope, inside P, x is B.x.</p> <p>Inside P, in the first instruction, we have the post-decrement y-- evaluated first, so the evaluated value would be 3 and B.x will change to 2.</p> <p>R is called by name, so the return (w + x++ + y++) will become return ++x + ++y + x++ + y++. The entire first expression is expanded to something equivalent to z = y-- + (++x + ++y + x++ + y++).</p> <p>In the expression ++x + ++y + x++ + y++, we have a pre-increment ++x, which will change B.x to 3 and give 3 as result. The ++y will change B.x to 4 and evaluate 4. The x++ will evaluate to 4 and change to 5 and the y++ will evaluate to 5 and change to 6.</p> <p>So the returned value from Q is 3 + 4 + 4 + 5 = 16. This will be added to the previous z-- value which is 3, so 19 will be assigned to z and B.x will be 6.</p> <p>The write will print x which is due to dynamic scope B.x, so will print 6. The y is a reference to the same B.x, so will print 6. The z is 19. <strong>So it will print 6, 6, 19</strong>.</p> <p>In the third instruction of the P, we have z = R(z++) which due to call by name will expand to something equivalent to z = (z++ + x++ + y++).</p> <p>So we get the z value, which is 19 and increment to 20 (post-increment). Add it to the value of B.x (6) and change B.x to 7. Add the 7 from y and increment y (which is B.x) to 8. So z = 19 + 6 + 7 = 32. B.x is 8.</p> <p>Due to the valueresult of z, the A.y will be changed to 32.</p> <p>Outside P, the write(y++, x++) will get the A.y value, which is 32 and print it. Then A.y will change to 33. B.x which is 8 will be printed and changed to 9. <strong>So it will print 32, 8</strong>.</p> <p>Finally, the A.y will be printed (its value is 33). The A.x will be printed, which is 5. <strong>So it will print 33, 5</strong>.</p> <p>Concluding, the program prints <strong>6, 6, 19, 32, 8, 33, 5</strong>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload