Compiler Construction MCQs with Answers
Practice important Compiler Construction MCQs with answers and explanations.
Chapter: 42
Q1121:
Which code generation strategy improves code by considering past and future use of data?
A. Simple code generation
B. Optimized code generation
C. Register allocation
D. Instruction scheduling
Correct Answer:
B
Chapter: 43
Q1122:
What does the triplet CFG = <V, E, Entry> represent?
A. A set of variables and functions
B. A control flow graph with vertices, edges, and program entry
C. A data structure for memory management
D. A type of compiler optimization
Correct Answer:
B
Chapter: 43
Q1123:
In a control flow graph, what do vertices (V) represent?
A. Program variables
B. Instructions or basic blocks
C. Memory addresses
D. Compiler errors
Correct Answer:
B
Chapter: 43
Q1124:
What does the set E represent in a control flow graph?
A. Vertices
B. Edges representing control flow between blocks
C. Source code lines
D. Syntax trees
Correct Answer:
B
Chapter: 43
Q1125:
The Entry in CFG is:
A. A set of exit points
B. A unique program entry point
C. A list of variables
D. A pointer to memory
Correct Answer:
B
Chapter: 43
Q1126:
Which of the following best defines a basic block?
A. A sequence of instructions with multiple entries and exits
B. A sequence of consecutive statements with single entry and single exit
C. A single statement in a program
D. A conditional statement
Correct Answer:
B
Chapter: 43
Q1127:
Which of these is NOT a variant of basic blocks?
A. Single entry/multiple exit
B. Multiple entry/single exit
C. Multiple entry/multiple exit
D. Single entry/single exit
Correct Answer:
C
Chapter: 43
Q1128:
How are basic blocks generated from intermediate code?
A. By partitioning the code into blocks based on leaders
B. By sorting variables alphabetically
C. By removing all goto statements
D. By merging functions
Correct Answer:
A
Chapter: 43
Q1129:
What qualifies a statement as a leader in partitioning basic blocks?
A. The first statement
B. A target of any goto
C. A statement immediately following a goto statement
D. All of the above
Correct Answer:
D
Chapter: 43
Q1130:
In three-address code, what does an unconditional goto instruction do in the CFG?
A. Creates no edges
B. Creates a single edge to another or same block
C. Creates multiple edges
D. Ends the program
Correct Answer:
B
Chapter: 43
Q1131:
If there is no goto at the end of a block, where does control pass?
A. To the previous block
B. To the first statement of the next block
C. To a random block
D. To the program exit
Correct Answer:
B
Chapter: 43
Q1132:
What is the role of the 'partition' algorithm in CFG generation?
A. To execute the program faster
B. To group three-address statements into basic blocks
C. To delete unreachable code
D. To optimize memory usage
Correct Answer:
B
Chapter: 43
Q1133:
In the dot product example, how many basic blocks are formed?
A. One
B. Two
C. Three
D. Four
Correct Answer:
B
Chapter: 43
Q1134:
In the dot product code, which statement type indicates a leader?
A. The first statement
B. The target of a conditional goto
C. The statement following a goto
D. All of the above
Correct Answer:
D
Chapter: 43
Q1135:
In CFG, what does an edge from one basic block to another represent?
A. Variable assignment
B. Control flow
C. Function call
D. Memory allocation
Correct Answer:
B
Chapter: 43
Q1136:
Which of the following is true about the quicksort algorithm example?
A. It uses recursion
B. It is iterative only
C. It uses only unconditional gotos
D. It does not use basic blocks
Correct Answer:
A
Chapter: 43
Q1137:
What is the first step in computing live/next use information?
A. Removing all variables
B. Initializing live set with all non-temporary variables
C. Generating basic blocks
D. Emitting machine code
Correct Answer:
B
Chapter: 43
Q1138:
In liveness analysis, a variable is live if:
A. It is defined in the program
B. It has a next use
C. It is used in the current statement
D. It is a temporary variable
Correct Answer:
B
Chapter: 43
Q1139:
What is the purpose of computing live variables at each statement?
A. To optimize memory usage
B. To generate faster code
C. To know which variables' values need to be preserved
D. To detect errors in code
Correct Answer:
C
Chapter: 43
Q1140:
For the statement "x = y + z", what variables get added to the live set?
A. y and z
B. x only
C. x and y
D. z only
Correct Answer:
A