GATE Computer ScienceModerateGATE CS (PYQ pattern)

For the code 1: x = 0; 2: y = 1; 3: L1: if x > n goto L4; 4: if y > m goto L2; 5: y = y + x; 6: goto L3; 7: L2: x = x + 2; 8: L3: x = x + 1; 9: goto L1; 10: L4: return y (n and m are inputs), how many variables are live immediately after statement 2 (y = 1)?

  1. A. 2
  2. B. 4
  3. C. 6
  4. D. 5

Correct answer: B. 4

Live after 2: ['m', 'n', 'x', 'y']; x, y are needed by the loop and the return, n and m by the tests.

More Compiler Design questions

Exams that ask this topic