GATE Computer ScienceHardGATE CS (PYQ pattern)

For the code 1: i = 0; 2: s = 0; 3: L1: if i >= n goto L4; 4: t = a + i; 5: if t > m goto L2; 6: s = s + t; 7: goto L3; 8: L2: a = a - 1; 9: L3: i = i + 1; 10: goto L1; 11: L4: return s, which definitions (named by statement number) reach the entry of statement 7 (goto L3)?

  1. A. 4, 6 and 9
  2. B. 1, 4, 6, 8 and 9
  3. C. 1, 2, 4, 6, 8 and 9
  4. D. 4, 6, 8 and 9

Correct answer: B. 1, 4, 6, 8 and 9

Statement 7 is reached only through 6, so the s-definition 2 is killed by 6 (s = s + t). For i, both 1 (first iteration) and 9 (around the back edge) reach, since nothing between them and 7 redefines i. t comes from 4; a's definition 8 reaches on the path 8 → 9 → 10 → 3 → 4 → 5 → 6 → 7. Hence {1, 4, 6, 8, 9}.

More Compiler Design questions

Exams that ask this topic