Skip to main content

GATE CSE 2014Compiler Design › Runtime Environments & Parameter PassingVerified

GATE CSE 2014 PYQ: Which of the following statements are CORRECT? Static allocation of all data areas by a compiler makes it…

Which of the following statements are CORRECT?

  1. Static allocation of all data areas by a compiler makes it impossible to implement recursion. 
  2. Automatic garbage collection is essential to implement recursion. 
  3. Dynamic allocation of activation records is essential to implement recursion. 
  4. Both heap and stack are essential to implement recursion. 
  1. A
    1 and 2 only
  2. B
    2 and 3 only
  3. C
    3 and 4 only
  4. D
    1 and 3 only
    Correct answer

Answer

(D) 1 1 1 and 3 3 3 only

Approach

Test each statement against the runtime requirement for recursion: a recursive function may have several invocations alive at once, so each invocation needs its own activation record. That forces dynamic allocation of activation records, normally on the call stack. Nothing about garbage collection or heap allocation is inherently required.

Recursion needs multiple simultaneously live activation records, so dynamic allocation of activation records is essential and fully static allocation makes recursion impossible. Garbage collection and heap allocation are not required, so statements 1 and 3 only are correct, giving option D.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.