Run-time Environments and Storage Allocation # MCQs Practice set

Q.1 Which of the following is responsible for managing memory during program execution?

Assembler
Loader
Linker
Run-time system
Explanation - The run-time system manages memory allocation and deallocation during program execution.
Correct answer is: Run-time system

Q.2 In compiler design, activation records are used to store information about:

Machine instructions
Function calls
Symbol table
Intermediate code
Explanation - Activation records hold information related to a single function call, such as parameters, return address, and local variables.
Correct answer is: Function calls

Q.3 Which storage allocation strategy assigns memory to variables at compile time?

Dynamic allocation
Heap allocation
Stack allocation
Static allocation
Explanation - Static allocation assigns memory at compile time and cannot be changed during execution.
Correct answer is: Static allocation

Q.4 Heap allocation is primarily used for:

Recursive function calls
Global variables
Dynamic memory requests
Static arrays
Explanation - Heap allocation allows memory to be allocated dynamically during program execution.
Correct answer is: Dynamic memory requests

Q.5 Which storage allocation strategy is most suitable for recursive procedures?

Static allocation
Stack allocation
Heap allocation
Register allocation
Explanation - Stack allocation allows each function call to get its own activation record, making recursion possible.
Correct answer is: Stack allocation

Q.6 The run-time environment ensures that:

Lexical analysis is done correctly
Memory is allocated and freed
Intermediate code is optimized
Parsing tables are constructed
Explanation - The run-time environment is responsible for managing memory during execution.
Correct answer is: Memory is allocated and freed

Q.7 Which of the following is stored in an activation record?

Intermediate code
Return address
Object code
Source code
Explanation - Activation records store return addresses, local variables, parameters, and bookkeeping information.
Correct answer is: Return address

Q.8 The memory area where global variables are stored is usually:

Stack
Heap
Code segment
Data segment
Explanation - Global variables are stored in the data segment of memory.
Correct answer is: Data segment

Q.9 Which allocation mechanism supports variable-sized objects?

Static allocation
Stack allocation
Heap allocation
Register allocation
Explanation - Heap allocation allows variable-sized memory blocks to be allocated dynamically.
Correct answer is: Heap allocation

Q.10 What happens when a function call is made?

A new process starts
A new activation record is pushed onto the stack
Memory is allocated in the heap
Compiler is re-invoked
Explanation - Each function call creates an activation record that is pushed onto the call stack.
Correct answer is: A new activation record is pushed onto the stack

Q.11 Which of the following is true about static allocation?

Memory is allocated at run-time
Memory cannot be reused
It allows recursion
It is managed by garbage collector
Explanation - In static allocation, memory is fixed and cannot be reused for recursive calls.
Correct answer is: Memory cannot be reused

Q.12 Garbage collection is used in which allocation strategy?

Stack allocation
Static allocation
Heap allocation
Register allocation
Explanation - Garbage collection reclaims memory from dynamically allocated heap objects that are no longer referenced.
Correct answer is: Heap allocation

Q.13 Which of the following is NOT part of an activation record?

Local variables
Return address
Intermediate code
Parameters
Explanation - Activation records store runtime information, not intermediate representation.
Correct answer is: Intermediate code

Q.14 Dynamic scoping requires:

Stack allocation
Heap allocation
Register allocation
Static allocation
Explanation - Dynamic scoping requires stack traversal to find the variable's binding at runtime.
Correct answer is: Stack allocation

Q.15 Which data structure best represents memory allocation for recursion?

Queue
Stack
Linked list
Array
Explanation - Stack is the ideal structure since recursion requires LIFO storage for activation records.
Correct answer is: Stack

Q.16 The size of activation record is determined during:

Linking
Compilation
Execution
Optimization
Explanation - The compiler determines the size of the activation record before execution.
Correct answer is: Compilation

Q.17 Which allocation scheme may lead to fragmentation?

Static allocation
Stack allocation
Heap allocation
Register allocation
Explanation - Heap allocation may cause fragmentation due to variable-sized requests.
Correct answer is: Heap allocation

Q.18 In stack allocation, local variables are:

Allocated once at compile time
Allocated and deallocated with each function call
Stored in heap
Stored in registers only
Explanation - Local variables are created when a function is called and destroyed when it returns.
Correct answer is: Allocated and deallocated with each function call

Q.19 Which memory allocation strategy is least flexible?

Heap allocation
Stack allocation
Static allocation
Dynamic allocation
Explanation - Static allocation does not allow changes at runtime, making it the least flexible.
Correct answer is: Static allocation

Q.20 The memory allocated for constants is usually in:

Heap
Code segment
Stack
Data segment
Explanation - Constants are stored in the read-only section of the data segment.
Correct answer is: Data segment

Q.21 Register allocation is done during:

Run-time
Compile-time
Link-time
Load-time
Explanation - Register allocation is decided by the compiler to optimize CPU register usage.
Correct answer is: Compile-time

Q.22 Which of the following supports dynamic memory management?

Malloc/Free
If-Else
Switch
Goto
Explanation - Dynamic memory is managed using malloc/free (C) or new/delete (C++).
Correct answer is: Malloc/Free

Q.23 In stack allocation, memory is released when:

The program ends
Function call returns
Garbage collector runs
Compilation ends
Explanation - When a function returns, its activation record is popped off the stack, releasing memory.
Correct answer is: Function call returns

Q.24 Which segment of memory stores the executable instructions?

Stack
Heap
Code segment
Data segment
Explanation - The code segment contains the compiled machine instructions of the program.
Correct answer is: Code segment

Q.25 Which type of allocation requires knowledge of the entire program beforehand?

Heap allocation
Static allocation
Stack allocation
Dynamic allocation
Explanation - Static allocation requires prior knowledge of program variables and their memory requirements.
Correct answer is: Static allocation