Compiler Design MCQ Questions And Answers - Code Optimization
This section focuses on "Code Optimization" in Compiler Design. These Multiple Choice Questions (MCQ) should be practiced to improve the Compiler Design skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Optimization can be categorized broadly into ____ types.
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : A
Explanation: Optimization can be categorized broadly into two types : machine independent and machine dependent.
2. A fragment of code that resides in the loop and computes the same value at each iteration is called a?
A. Induction analysis
B. Strength reduction
C. loop-invariant code
D. None of the above
View Answer
Ans : C
Explanation: A fragment of code that resides in the loop and computes the same value at each iteration is called a loop-invariant code. This code can be moved out of the loop by saving it to be computed only once, rather than with each iteration.
3. A variable is called an _________ variable if its value is altered within the loop by a loop-invariant value.
A. Invariant
B. induction
C. strength
D. loop
View Answer
Ans : B
Explanation: Induction analysis : A variable is called an induction variable if its value is altered within the loop by a loop-invariant value.
4. Dead code plays no role in any program operation and therefore it can simply be eliminated.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: dead code plays no role in any program operation and therefore it can simply be eliminated.
5. Substitution of values for names whose values are constant, is done in
A. local optimization
B. loop optimization
C. constant folding
D. None of the above
View Answer
Ans : C
Explanation: Substitution of values for names whose values are constant, is done in constant folding
6. Peep-hole optimization is a form of
A. loop optimization
B. local optimization
C. data flow analysis
D. constant folding
View Answer
Ans : D
Explanation: Redundant instructions may be discarded during the final stage of compilation by using a simple optimizing technique called peephole optimization.It is a kind of optimization performed over a very small set of instructions in a segment of generated code. The set is called a peephole or a window.
7. In analyzing the compilation of PL/I program, the term Machine independent optimization is assosiated with
A. creation of more optical matrix
B. recognition of basic elements and creation of uniform symbols
C. recognization of basic syntactic construction through reductionsc
D. use of macro-processor to produce more optimal assembly code
View Answer
Ans : A
Explanation: In analyzing the compilation of PL/I program, the term Machine independent optimization is assosiated with creation of more optical matrix
8. Before generating intermediate code, the compiler can modify the intermediate code by address calculations and improving loops.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : B
Explanation: After generating intermediate code, the compiler can modify the intermediate code by address calculations and improving loops.
9. The compiler can make use of memory hierarchy and CPU registers.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: While producing the target machine code, the compiler can make use of memory hierarchy and CPU registers.
10. A compiler for a high-level language that runs on one machine and produces code for a different machine is called
A. optimizing compiler
B. one pass compiler
C. cross compiler
D. multipass compiler
View Answer
Ans : C
Explanation: A compiler for a high-level language that runs on one machine and produces code for a different machine is called cross compiler.
Discussion