Skip to content
Official PYQ · 1998

GATE CS 1998 Q2.15 — Runtime Environments

Explain with AI

Faster access to non-local variables is achieved using an array of pointers to activation records called a 

Choose one option
View worked solution

Answer: C

The correct option is C.

In block-structured programming languages (such as Pascal), nested procedures can access variables declared in outer scopes (non-local variables). There are two primary techniques to implement this access:

  • Static Links (Access Links): Accessing a non-local variable requires traversing a chain of pointers. If the variable is declared at a nesting depth dd levels shallower than the current procedure, we must traverse dd links, which takes O(d)O(d) time.
  • Display: To achieve faster, constant-time (O(1)O(1)) access to non-local variables, compilers use an auxiliary array of pointers called a display.

The ii-th entry of the display array points to the activation record of the most recently active procedure at nesting depth ii. Any non-local variable at nesting depth ii can be accessed directly in O(1)O(1) time by dereferencing the pointer at index ii of the display, followed by the local offset.

Why other options are incorrect:

  • Stack: Used to store activation records in a Last-In-First-Out (LIFO) order, but does not directly provide O(1)O(1) access to non-local variables in nested scopes.
  • Heap: Used for dynamic memory allocation (e.g., objects, lifetime extending beyond procedure calls).
  • Activation Tree: A conceptual tree representing the entry and exit of control among various activation records during execution. It is not a data structure used for variable access.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Runtime Environments questions