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 (only s is used after the return), which set is exactly the set of variables live on entry to statement 1?

  1. A. {a, m, n}
  2. B. {m, n}
  3. C. {a, m, n, s}
  4. D. {a, i, m, n}

Correct answer: A. {a, m, n}

Live on entry = used before being defined along some path. i, s and t are all assigned before any use (statements 1, 2, 4). a is read in statement 4 before statement 8 can assign it, m in statement 5, n in statement 3. So {a, m, n}; the assignment a = a − 1 does not stop a from being live, because a is read first.

More Compiler Design questions

Exams that ask this topic