Runtime Environments
Runtime Environments” from Compiler Design for the GATE Exam
1.
In a runtime environment, which of the following regions typically grows downward in memory?
A) Heap
B) Code segment
C) Stack
D) Static data segment
✅ Answer: C) Stack
Solution:
In most architectures, the stack grows downward (toward lower memory addresses), while the heap grows upward. This allows both to share the same address space efficiently.
2.
Which of the following memory regions is used for dynamic memory allocation at runtime?
A) Stack
B) Static area
C) Heap
D) Code segment
✅ Answer: C) Heap
Solution:
The heap supports dynamic memory allocation (e.g., malloc() in C). Stack allocation is for local variables, while the static area holds global data.
3.
If a recursive function is called 6 times, how many activation records will be simultaneously present on the stack before any return occurs?
A) 1
B) 3
C) 6
D) 12
✅ Answer: C) 6
Solution:
Each recursive call generates a new activation record before any previous one returns, so all 6 are active simultaneously.
4.
An activation record typically does not contain:
A) Control link
B) Access link
C) Return value
D) Intermediate code
✅ Answer: D) Intermediate code
Solution:
Intermediate code exists in compiler memory, not runtime. Activation records store control link, access link, parameters, and local variables.
5.
The access link in a runtime environment helps in:
A) Function call management
B) Accessing non-local variables
C) Storing return address
D) Handling recursion depth
✅ Answer: B) Accessing non-local variables
Solution:
In languages with nested functions, an access link connects activation records to access variables of enclosing scopes.
6.
If a function F calls G, and both belong to different nesting levels, then:
A) Control link connects F to main
B) Access link connects G to F
C) Control link connects G to F
D) Access link connects F to main
✅ Answer: B) Access link connects G to F
Solution:
The access link connects the callee’s activation record to the activation record of its lexical parent (the enclosing function).
7.
The display method is an optimization over:
A) Control link
B) Access link
C) Heap management
D) Symbol table
✅ Answer: B) Access link
Solution:
Displays are used instead of access links for faster access to non-local variables, especially in languages with deep nesting.
8.
Which of the following correctly matches?
| Concept | Purpose |
|---|---|
| Control link | Returns control to caller |
| Access link | Non-local variable access |
| Heap | Dynamic allocation |
A) All correct
B) Only first two
C) Only first and third
D) Only second
✅ Answer: A) All correct
Solution:
All mappings are accurate: control link → caller, access link → non-local variable, heap → dynamic memory.
9.
In a stack-based runtime environment, parameters are passed:
A) Always by reference
B) Using registers only
C) Via stack memory
D) Using heap
✅ Answer: C) Via stack memory
Solution:
Parameters are pushed on the stack before a function call, maintaining order and allowing recursion.
10.
Which field in the activation record stores the address of the calling function’s activation record?
A) Access link
B) Control link
C) Return address
D) Parameter field
✅ Answer: B) Control link
Solution:
Control link points to the caller’s activation record, enabling proper return after function completion.
11.
In a language without nested procedures, the access link is:
A) Required for recursion
B) Not needed
C) Used for parameter passing
D) Used for dynamic memory
✅ Answer: B) Not needed
Solution:
Access links are used for non-local variable access in nested scopes. If no nesting exists, they are unnecessary.
12.
Garbage collection is required primarily in:
A) Stack-based allocation
B) Static memory allocation
C) Heap-based allocation
D) Code segment
✅ Answer: C) Heap-based allocation
Solution:
Objects in heap persist beyond function calls; garbage collection reclaims unused heap memory.
13.
In static memory allocation, memory is assigned:
A) During program execution
B) At compile time
C) By the loader
D) Using heap
✅ Answer: B) At compile time
Solution:
Static variables and global objects get memory during compilation, not at runtime.
14.
A runtime stack overflow typically occurs when:
A) Too many dynamic allocations
B) Too many nested function calls
C) Code segment is large
D) Heap is full
✅ Answer: B) Too many nested function calls
Solution:
Each function call adds an activation record; excessive recursion exhausts stack space.
15.
If heap starts at address 2000 and stack starts at 8000, they will typically grow:
A) Both upward
B) Both downward
C) Toward each other
D) Away from each other
✅ Answer: C) Toward each other
Solution:
Heap grows upward, stack grows downward → they grow toward each other to use space efficiently.
16.
In a runtime environment, the region used for constants and literals is:
A) Code segment
B) Stack
C) Static data segment
D) Heap
✅ Answer: C) Static data segment
Solution:
Constants, literals, and global/static variables are stored in static data segment.
17.
When a function returns, which link is used to resume caller execution?
A) Control link
B) Access link
C) Return address
D) Display table
✅ Answer: C) Return address
Solution:
Return address in activation record tells the program where to continue after function execution.
18.
Which of the following is NOT true about heap memory?
A) Grows dynamically
B) Managed by the programmer or GC
C) Automatically deallocated when function returns
D) Used for dynamic data structures
✅ Answer: C) Automatically deallocated when function returns
Solution:
Heap memory persists until freed manually or by garbage collector; stack memory deallocates automatically.
19.
A runtime descriptor is used for:
A) Static scoping
B) Dynamic type checking
C) Parameter passing
D) Code generation
✅ Answer: B) Dynamic type checking
Solution:
Runtime descriptors store type information for dynamic type verification (used in polymorphic languages).
20.
In dynamic scoping, non-local variables are resolved using:
A) Access link
B) Control link
C) Symbol table
D) Display
✅ Answer: B) Control link
Solution:
In dynamic scoping, variable lookup follows the calling chain, which uses control links.
21.
Which runtime feature allows recursion in programs?
A) Static allocation
B) Stack allocation
C) Heap allocation
D) Register allocation
✅ Answer: B) Stack allocation
Solution:
Each recursive call creates a new stack frame (activation record), enabling separate variable instances.
22.
If function f1() calls f2() which calls f3(), the control link of f3() points to:
A) f1’s activation record
B) f2’s activation record
C) Global area
D) Stack base
✅ Answer: B) f2’s activation record
Solution:
Control link connects callee to the immediate caller, hence f3 → f2.
23.
The display table used in runtime environments stores:
A) Access links for each nesting level
B) Return addresses
C) Local variable addresses
D) Function call hierarchy
✅ Answer: A) Access links for each nesting level
Solution:
Display table provides direct pointers to activation records of various nesting levels for faster non-local access.
24.
Garbage collection can fail to reclaim memory in:
A) Stack
B) Heap
C) Static segment
D) Both A and B
✅ Answer: C) Static segment
Solution:
Static segment memory is fixed and globally accessible; garbage collector only manages heap memory.
25.
Which allocation strategy allows variables to outlive function calls?
A) Stack allocation
B) Static allocation
C) Register allocation
D) None
✅ Answer: B) Static allocation
Solution:
Static variables retain their values and memory across multiple function calls.
26.
If the nesting depth of functions is 4, what is the maximum number of activation records that can be linked via access links?
A) 3
B) 4
C) 2
D) 1
✅ Answer: A) 3
Solution: Access links connect to outer scopes; the innermost function links through 3 access links to the outermost level.
27.
When a function returns, its activation record is:
A) Moved to heap
B) Popped from stack
C) Copied to static area
D) Saved in display table
✅ Answer: B) Popped from stack
Solution: Activation records are pushed during calls and popped after return, freeing stack space automatically.
28.
Which of the following cannot be allocated statically?
A) Global variables
B) Local arrays with fixed size
C) Recursively created variables
D) Constants
✅ Answer: C) Recursively created variables
Solution: Recursion requires multiple activations; hence recursion variables need stack allocation, not static.
29.
Which part of an activation record stores information for nested scopes?
A) Control link
B) Access link
C) Return address
D) Parameter list
✅ Answer: B) Access link
Solution: The access link provides connectivity for accessing variables in enclosing scopes.
30.
Dynamic scoping primarily uses which runtime structure?
A) Symbol table
B) Control link
C) Heap
D) Access link
✅ Answer: B) Control link
Solution: Dynamic scoping uses the chain of calling functions, i.e., the control links to resolve variables.
31.
A static chain in a runtime environment represents:
A) Chain of functions in call order
B) Chain of static scopes
C) Heap allocation order
D) Constant data list
✅ Answer: B) Chain of static scopes
Solution: A static chain links activation records based on lexical nesting, used in static scoping.
32.
Which of the following best defines a display?
A) A table of pointers to activation records of different nesting levels
B) A queue of access links
C) A record of all return addresses
D) A heap memory allocator
✅ Answer: A)
Solution: Display is a fast lookup structure storing pointers to activation records by nesting depth.
33.
What happens if a function with deep recursion runs out of stack memory?
A) Heap overflow
B) Segmentation fault
C) Stack overflow
D) Static data corruption
✅ Answer: C)
Solution: Too many nested calls overflow the limited stack space, leading to stack overflow errors.
34.
Which memory region contains dynamically created linked list nodes?
A) Heap
B) Stack
C) Static
D) Code segment
✅ Answer: A)
Solution: Dynamic data structures like linked lists are allocated in heap space for flexible lifetimes.
35.
Which memory allocation model supports recursion and re-entrancy?
A) Static
B) Stack
C) Heap
D) Register
✅ Answer: B)
Solution: Stack allocation enables recursion and re-entrant calls by creating independent frames per call.
36.
If the maximum stack size is 8KB and each activation record is 256B, how many recursive calls are possible before overflow?
A) 16
B) 32
C) 64
D) 128
✅ Answer: C)
Solution: ( 8192 / 256 = 32 ) activation records can exist → after 32nd call, overflow happens.
37.
In a language with nested functions, which is more efficient for non-local access?
A) Static chain
B) Display
C) Heap pointer
D) Control link
✅ Answer: B)
Solution: Display tables allow direct O(1) access to variables of outer scopes, unlike static chain traversal.
38.
What component in runtime supports returning to the caller after execution?
A) Control link
B) Return address
C) Static chain
D) Access link
✅ Answer: B)
Solution: Return address tells CPU where to resume after the callee finishes.
39.
Which of the following is stored in the heap but not in the stack?
A) Function parameters
B) Global constants
C) Dynamically allocated arrays
D) Local variables
✅ Answer: C)
Solution: Dynamically created arrays go to heap; local and parameters go to stack.
40.
A variable in the static area remains allocated:
A) Until function returns
B) Until program terminates
C) Until heap is freed
D) Only during one block
✅ Answer: B)
Solution: Static/global variables live throughout the entire program execution.
41.
A runtime environment supports:
A) Lexical analysis
B) Execution-time storage management
C) Intermediate code generation
D) Code optimization
✅ Answer: B)
Solution: Runtime system manages stack, heap, and control flow at execution time.
42.
The field in activation record storing passed arguments is known as:
A) Parameter field
B) Access link
C) Control link
D) Static chain
✅ Answer: A)
Solution: Parameters from the caller are stored in a separate area within each activation record.
43.
If two functions in different modules share a global variable, it resides in:
A) Stack
B) Heap
C) Static area
D) Code segment
✅ Answer: C)
Solution: Global/static data are stored in static memory accessible across modules.
44.
Which field connects the currently executing procedure to its caller?
A) Control link
B) Access link
C) Return address
D) Display table
✅ Answer: A)
Solution: Control link connects the current activation record with the caller’s activation record.
45.
The term “environment pointer” usually refers to:
A) Pointer to heap top
B) Pointer to current activation record
C) Pointer to code segment
D) Pointer to return address
✅ Answer: B)
Solution: The environment pointer identifies the base of the currently active activation record.
46.
Garbage collection is unnecessary in:
A) Heap-based allocation
B) Stack-based allocation
C) Dynamic binding
D) Object-oriented languages
✅ Answer: B)
Solution: Stack memory is automatically reclaimed on function return — no GC needed.
47.
A dangling reference occurs when:
A) Memory is allocated twice
B) Stack frame is too large
C) A deallocated memory is accessed
D) Garbage collector fails
✅ Answer: C)
Solution: Accessing memory after freeing it leads to dangling references, common in heap.
48.
In a stack-based language implementation, local variables are stored:
A) Before parameters
B) After parameters
C) Both A and B possible
D) Only in heap
✅ Answer: C)
Solution: Depending on calling convention, locals may be placed before or after parameters.
49.
Which runtime structure stores the dynamic chain?
A) Heap
B) Static chain
C) Stack
D) Display
✅ Answer: C)
Solution: The stack naturally maintains the control (dynamic) chain of function calls.
50.
Which is NOT part of an activation record?
A) Local variables
B) Access link
C) Garbage collector flag
D) Return address
✅ Answer: C)
Solution: GC flag is part of heap management, not function stack management.
51.
Which type of memory allocation ensures fastest access?
A) Stack
B) Static
C) Heap
D) Disk
✅ Answer: B)
Solution: Static memory addresses are fixed; no runtime computation needed for access.
52.
In recursion, every call creates a separate:
A) Code segment
B) Activation record
C) Static link
D) Symbol table
✅ Answer: B)
Solution: Each call creates a unique activation record with its own parameters and locals.
53.
In a language supporting closures, environment pointers are stored:
A) On heap
B) On stack
C) In static area
D) Not stored
✅ Answer: A)
Solution: Closures capture environments; hence environment data must persist beyond function return (heap).
54.
The heap pointer always points to:
A) End of static area
B) Start of stack
C) Top of heap
D) Base of code
✅ Answer: C)
Solution: Heap pointer tracks the next free memory location for dynamic allocation.
55.
The function return value is typically stored:
A) On stack
B) In register
C) On heap
D) In static segment
✅ Answer: B)
Solution: Most architectures use CPU registers (like EAX in x86) for returning values.
56.
The runtime stack is also called:
A) Control stack
B) Memory stack
C) Code stack
D) Static stack
✅ Answer: A)
Solution: It maintains control of program flow via activation records → control stack.
57.
Dynamic memory fragmentation occurs mainly in:
A) Stack
B) Heap
C) Static memory
D) Code segment
✅ Answer: B)
Solution: Variable-sized allocations and deallocations in heap cause fragmentation.
58.
In a runtime environment, the frame pointer:
A) Points to start of stack
B) Points to current function’s activation record base
C) Points to return address
D) Tracks heap top
✅ Answer: B)
Solution: The frame pointer identifies the base of the current activation record for easy local access.
59.
The heap overflow occurs when:
A) Stack grows into heap
B) Heap grows into stack
C) Both A and B
D) Heap pointer crosses static area
✅ Answer: B)
Solution: When heap expands into stack’s region → heap overflow.
60.
Garbage collection may reclaim:
A) Inaccessible heap objects
B) All stack frames
C) Static data
D) Code segment
✅ Answer: A)
Solution: GC identifies and frees heap objects no longer reachable.
61.
Dynamic scoping uses which chain to resolve identifiers?
A) Static chain
B) Dynamic chain
C) Heap chain
D) Display chain
✅ Answer: B)
Solution: The dynamic chain (control link sequence) is used for variable resolution in dynamic scoping.
62.
If a function has 2 local variables and calls itself 3 times recursively, total local variable instances created are:
A) 2
B) 4
C) 6
D) 8
✅ Answer: C)
Solution: Each call creates 2 → 3 calls × 2 = 6 variable instances.
63.
Static variables in C retain values between calls because they are stored in:
A) Stack
B) Heap
C) Static data segment
D) Register
✅ Answer: C)
Solution: Static variables are stored in the static segment and initialized only once.
64.
Which runtime entity supports exception handling via stack unwinding?
A) Heap manager
B) Control stack
C) Static chain
D) Display table
✅ Answer: B)
Solution: The control stack unwinds activation records during exception propagation.
65.
When a subroutine is called, parameters are usually passed:
A) Through stack or registers
B) Through heap
C) Via static table
D) Through file system
✅ Answer: A)
Solution: Parameters are passed using stack frames or registers depending on calling convention.
66.
A runtime descriptor contains:
A) Type and memory info of objects
B) Code optimization flags
C) Compiler metadata only
D) Parameter count only
✅ Answer: A)
Solution: Runtime descriptors hold type, size, and other data for runtime type checking.
67.
Which runtime structure ensures variables of outer functions remain accessible in nested scopes?
A) Access link
B) Control link
C) Display table
D) Static chain
✅ Answer: D)
Solution: Static chain represents lexical scope links for non-local variable access.
68.
Garbage collection can’t reclaim memory:
A) Accessible by variable
B) Lost pointer data
C) Cyclic references (without special GC)
D) None of these
✅ Answer: C)
Solution: Simple reference-count GC can’t handle cyclic references.
69.
Which one gives the slowest access time?
A) Static memory
B) Stack memory
C) Heap memory
D) Register memory
✅ Answer: C)
Solution: Heap involves dynamic lookup and management; thus, it’s slowest.
70.
In C, local arrays are allocated in:
A) Heap
B) Stack
C) Static
D) None
✅ Answer: B)
Solution: Local arrays are automatic variables; they’re stored on the stack.
71.
The runtime system is responsible for:
A) Managing runtime memory
B) Parsing source code
C) Lexical analysis
D) Intermediate code generation
✅ Answer: A)
Solution: It handles memory management, control flow, and stack/heap maintenance during execution.
72.
When two functions share the same global variable, runtime access is through:
A) Access link
B) Static area
C) Heap
D) Stack
✅ Answer: B)
Solution: Global/static data are kept in the static area, shared by all functions.
73.
If recursion depth is limited to 256 and each frame is 64 bytes, required stack size is:
A) 8 KB
B) 16 KB
C) 32 KB
D) 64 KB
✅ Answer: A)
Solution: (256 × 64 = 16384) bytes = 16 KB.
74.
Dangling pointers are more common in:
A) Stack
B) Heap
C) Static
D) Code segment
✅ Answer: B)
Solution: Heap allocations may be freed while pointers still reference them → dangling pointer.
75.
To support first-class functions, environments are stored in:
A) Static
B) Heap
C) Stack
D) Registers
✅ Answer: B)
Solution: First-class functions may outlive callers; hence environment captured on heap.
76.
A variable accessible by any function at runtime is stored in:
A) Stack
B) Heap
C) Static segment
D) Register
✅ Answer: C)
Solution: Global/static variables have global visibility.
77.
The stack grows downward because:
A) Heap grows upward
B) Registers are fixed
C) Memory is limited
D) OS restriction
✅ Answer: A)
Solution: Opposite growth direction for stack and heap allows flexible sharing of address space.
78.
Lexical nesting in runtime is represented by:
A) Control link chain
B) Static chain
C) Display
D) Access link
✅ Answer: B)
Solution: Static chain connects activation records based on lexical scope hierarchy.
79.
The dynamic chain represents:
A) Calling sequence of functions
B) Scope hierarchy
C) Heap links
D) Global data chain
✅ Answer: A)
Solution: Dynamic chain traces actual call order, used in dynamic scoping.
80.
When a function calls another, the return address is stored in:
A) Stack
B) Heap
C) Static
D) Display
✅ Answer: A)
Solution: Return address is stored in activation record on the stack.
81.
A runtime environment that supports coroutines requires:
A) Separate stacks
B) Common heap
C) Shared control links
D) Global data
✅ Answer: A)
Solution: Coroutines maintain independent stacks for suspending/resuming executions.
82.
A closure is a combination of:
A) Code + Activation Record
B) Function + Environment
C) Heap + Stack
D) Static + Dynamic Link
✅ Answer: B)
Solution: Closure = function + captured environment for later invocation.
83.
Heap allocation is slower than stack because:
A) Stack uses LIFO
B) Heap uses search and fragmentation control
C) Stack is static
D) Heap is small
✅ Answer: B)
Solution: Heap management involves allocation and deallocation with fragmentation overhead.
84.
The lifetime of a heap variable is:
A) Fixed
B) Dynamic
C) Static
D) Recursive
✅ Answer: B)
Solution: Heap variables live as long as explicitly retained (dynamic lifetime).
85.
Stack frame is created:
A) When function is called
B) At compile time
C) By linker
D) When heap overflows
✅ Answer: A)
Solution: Each function call dynamically creates a stack frame at runtime.
86.
Memory leak occurs when:
A) Stack frame not removed
B) Freed memory reused
C) Heap memory unreachable but not freed
D) Static variable reused
✅ Answer: C)
Solution: Unreachable heap memory that remains allocated → memory leak.
87.
Recursive function depth is limited by:
A) Heap size
B) Stack size
C) Static memory
D) Compiler version
✅ Answer: B)
Solution: Each call consumes stack → recursion depth limited by stack capacity.
88.
Garbage collectors use which strategy to detect unused objects?
A) Mark and sweep
B) LIFO
C) FIFO
D) Static linking