Which of the following are true? I. A programming language which does not…

2008

Which of the following are true?

I. A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation

II. Multi-level access link (or display) arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions

III. Recursion in programming languages cannot be implemented with dynamic storage allocation

IV. Nesting of procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records

V. Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records

Answer: A. II and V onlyAnswer: II and V only Statement I (A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but…

  1. A.

    II and V only

  2. B.

    I, III and IV only

  3. C.

    I, II and V only

  4. D.

    II, III and V only

Attempted by 34 students.

Show answer & explanation

Correct answer: A

Answer: II and V only

  • Statement I (A programming language which does not permit global variables of any kind and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation): False. Recursion requires multiple simultaneous activation records for nested calls, so a single compile-time/static allocation cannot support general recursion. A dynamic scheme such as a call stack or heap allocation is needed.

  • Statement II (Multi-level access link or display arrangement is needed to arrange activation records only if the programming language being implemented has nesting of procedures/functions): True. Access links or displays are mechanisms to locate nonlocal variables in lexically nested scopes. If the language has no nesting, these mechanisms are not required.

  • Statement III (Recursion in programming languages cannot be implemented with dynamic storage allocation): False. In practice recursion is implemented using dynamic storage allocation (for example, pushing a new activation record on the call stack for each call). Dynamic allocation is exactly what enables recursion.

  • Statement IV (Nesting of procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records): False. A stack-based allocation combined with static links or a display can support both nesting (access to nonlocal variables) and recursion. Heap allocation becomes necessary only when activation records must outlive their caller (for example, when returning closures that reference locals).

  • Statement V (Programming languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records): True (in the common/standard case). If returned functions can close over local variables, those activation records must remain valid after the calling function returns; a simple stack discipline that reclaims frames on return cannot provide that. Implementations therefore use heap allocation for such activation records or copy the needed environment into a heap-allocated closure.

Conclusion: Only the statements about multi-level access links being needed only with nesting and about returned functions requiring activation records to persist are correct, so the true statements are II and V.

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…