☑ MCQ PRACTICE

Compiler Design Unit 4

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

📚 Compiler Design
📖 Unit 4
🎯 MCQs
Compiler Design MCQs - Unit 4

Compiler Design MCQs - Unit 4

1

An activation record stores

A the entire source program
B the symbol table
C only global variables
D information needed for a single execution of a procedure
Correct Answer information needed for a single execution of a procedure
2

In stack allocation, activation records are

A pushed on a procedure call and popped on return
B stored in the heap
C never removed
D stored in the source file
Correct Answer pushed on a procedure call and popped on return
3

The control link in an activation record points to

A the heap
B the activation record of the caller
C the next instruction
D the global data
Correct Answer the activation record of the caller
4

The access link is used to

A return a value
B reach nonlocal data under static scoping
C store temporaries
D save registers
Correct Answer reach nonlocal data under static scoping
5

A display is

A a list of tokens
B a type of register
C an array of pointers to activation records used for nonlocal access
D a screen buffer
Correct Answer an array of pointers to activation records used for nonlocal access
6

The heap is used for

A dynamically allocated data whose lifetime is not tied to a procedure
B only local variables
C only return addresses
D only constants
Correct Answer dynamically allocated data whose lifetime is not tied to a procedure
7

A dangling pointer is a pointer to

A memory that is not yet allocated
B memory that has already been freed
C a register
D the stack top
Correct Answer memory that has already been freed
8

A memory leak occurs when

A memory is freed twice
B the stack overflows
C allocated memory is never freed and cannot be reached
D a pointer is null
Correct Answer allocated memory is never freed and cannot be reached
9

Garbage collection is the automatic

A reclamation of memory that is no longer reachable
B compilation of programs
C creation of tokens
D allocation of registers
Correct Answer reclamation of memory that is no longer reachable
10

A weakness of reference counting is that it cannot reclaim

A all garbage
B cyclic garbage
C any stack data
D constants
Correct Answer cyclic garbage
11

Mark-and-sweep garbage collection first

A marks all reachable objects and then sweeps the unmarked ones
B deletes everything and restarts
C sorts the objects by size
D compiles the objects
Correct Answer marks all reachable objects and then sweeps the unmarked ones
12

Trace-based collection starts from the

A leaf set
B root set
C free list
D symbol table
Correct Answer root set
13

A basic block is a sequence of statements with

A a single entry and a single exit
B many entries and one exit
C one entry and many exits
D no entry
Correct Answer a single entry and a single exit
14

The first statement of a basic block is called a

A header
B leader
C handle
D sentinel
Correct Answer leader
15

In a flow graph, the nodes are

A tokens
B basic blocks
C registers
D variables
Correct Answer basic blocks
16

A DAG for a basic block helps in

A eliminating common subexpressions
B adding new loops
C increasing code size
D scanning tokens
Correct Answer eliminating common subexpressions
17

Peephole optimization examines

A the entire program at once
B only the symbol table
C a small window of target instructions
D only comments
Correct Answer a small window of target instructions
18

Which of the following is a peephole optimization?

A Adding more variables
B Increasing loop count
C Removing the main function
D Eliminating redundant loads and stores
Correct Answer Eliminating redundant loads and stores
19

Register allocation can be modelled using

A binary search
B hashing only
C graph coloring
D tokenising
Correct Answer graph coloring
20

Which of the following is an issue in the design of a code generator?

A Instruction selection
B Lexeme counting
C Comment removal
D Token naming
Correct Answer Instruction selection
21

Replacing x * 2 by x + x is an example of

A strength reduction
B dead-code elimination
C loop unrolling
D constant folding
Correct Answer strength reduction
22

Replacing x + 0 by x is an example of

A register spilling
B backpatching
C inlining
D algebraic simplification
Correct Answer algebraic simplification
23

Dynamic programming code generation is used to generate optimal code for

A expression trees
B lexical analysis
C string matching
D linking
Correct Answer expression trees
24

The input to the code generator is the intermediate representation together with

A the source comments
B the token list only
C the object file
D the symbol table
Correct Answer the symbol table
25

In a stack-based environment, local variables are accessed relative to

A the frame (stack) pointer
B the heap base only
C the program counter only
D the file pointer
Correct Answer the frame (stack) pointer

Fill in the Blanks

26 An ______ record stores the information needed for one execution of a procedure.
Correct Answer activation
27 The ______ link in an activation record points to the caller's activation record.
Correct Answer control
28 The ______ link is used to access nonlocal data under static scoping.
Correct Answer access
29 Dynamically allocated data with an unknown lifetime is stored in the ______.
Correct Answer heap
30 A pointer to memory that has already been freed is called a ______ pointer.
Correct Answer dangling
31 Reference counting cannot reclaim ______ structures.
Correct Answer cyclic
32 Mark-and-sweep garbage collection has two phases: mark and ______.
Correct Answer sweep
33 A basic block has a single entry and a single ______.
Correct Answer exit
34 The first statement of a basic block is called a ______.
Correct Answer leader
35 In a flow graph, the nodes are ______.
Correct Answer basic blocks
36 Peephole optimization examines a small ______ of instructions.
Correct Answer window
37 Strength reduction replaces expensive operations with ______ ones.
Correct Answer cheaper
38 Register allocation can be done using graph ______.
Correct Answer coloring
39 A DAG helps in common ______ elimination within a basic block.
Correct Answer subexpression
40 Replacing x * 8 with x << 3 is an example of ______ reduction.
Correct Answer strength
← Back to All MCQs