1. Which of the following is the primary goal of loop optimization?
A) To remove unnecessary loops
B) To reduce the number of instructions in the loop body
C) To make the loop more readable
D) To increase the size of the loop
Answer: B) To reduce the number of instructions in the loop body
2. What does constant folding optimization do?
A) It removes loops that do not execute
B) It evaluates constant expressions at compile time
C) It eliminates dead code
D) It converts loops into functions
Answer: B) It evaluates constant expressions at compile time
3. Dead code elimination removes code that:
A) Will never be executed because it is unreachable
B) Is part of the program’s functionality but has no effect
C) Is redundant in terms of calculations
D) Is unnecessary for memory management
Answer: A) Will never be executed because it is unreachable
4. Which of the following optimizations is aimed at reducing the number of loop iterations?
A) Loop unrolling
B) Constant folding
C) Strength reduction
D) Dead code elimination
Answer: A) Loop unrolling
5. Which optimization technique involves replacing a function call with the value of an expression when the expression is constant at compile time?
A) Dead code elimination
B) Inline expansion
C) Constant propagation
D) Constant folding
Answer: D) Constant folding
6. In dead code elimination, which of the following types of code would typically be removed?
A) Code that does not modify the program’s state
B) Code that is called but never executed
C) Code that is never reached during program execution
D) Code that causes an error
Answer: C) Code that is never reached during program execution
7. What is the effect of loop unrolling optimization?
A) It makes the code more readable by breaking loops into smaller steps
B) It reduces the number of iterations in the loop
C) It reduces the overhead of loop control by increasing the number of instructions inside the loop
D) It optimizes memory access patterns in the loop
Answer: C) It reduces the overhead of loop control by increasing the number of instructions inside the loop
8. Which of the following is an example of a common optimization technique that eliminates unnecessary calculations in loops?
A) Loop fusion
B) Loop splitting
C) Loop invariant code motion
D) Loop unrolling
Answer: C) Loop invariant code motion
9. Which optimization technique evaluates constant expressions during compile-time and replaces them with their values?
A) Constant folding
B) Loop optimization
C) Dead code elimination
D) Strength reduction
Answer: A) Constant folding
10. Which of the following techniques is used to replace expressions in loops with simpler ones by pre-computing constant expressions?
A) Loop unrolling
B) Constant propagation
C) Loop invariant code motion
D) Strength reduction
Answer: B) Constant propagation
11. Which of the following is an example of a loop optimization technique?
A) Constant folding
B) Dead code elimination
C) Loop unrolling
D) Function inlining
Answer: C) Loop unrolling
12. What is the primary benefit of strength reduction in optimization?
A) It reduces the strength of operators to less costly ones
B) It removes unnecessary code
C) It makes loops more efficient
D) It simplifies expressions in the code
Answer: A) It reduces the strength of operators to less costly ones
13. Which optimization technique is used to eliminate computations that do not contribute to the final result?
A) Loop unrolling
B) Constant folding
C) Dead code elimination
D) Constant propagation
Answer: C) Dead code elimination
14. Which of the following optimizations is most effective when dealing with repeated calculations in loops?
A) Constant folding
B) Strength reduction
C) Loop invariant code motion
D) Function inlining
Answer: C) Loop invariant code motion
15. In which scenario is constant propagation most effective?
A) When variables are frequently reassigned new values
B) When there are loops with complex conditions
C) When variables are assigned constant values across the program
D) When a program uses a lot of conditional branches
Answer: C) When variables are assigned constant values across the program
16. Which of the following optimizations is aimed at reducing the size of the code by eliminating unused or redundant code?
A) Constant folding
B) Dead code elimination
C) Strength reduction
D) Instruction scheduling
Answer: B) Dead code elimination
17. Which optimization technique can reduce the number of executed instructions by combining multiple instructions into a single instruction?
A) Constant folding
B) Peephole optimization
C) Dead code elimination
D) Strength reduction
Answer: B) Peephole optimization
18. Which of the following is an example of strength reduction optimization in a loop?
A) Replacing a multiplication by a constant with an addition
B) Removing loop control instructions
C) Removing dead branches in conditional statements
D) Replacing a division operation with a multiplication by the reciprocal
Answer: A) Replacing a multiplication by a constant with an addition
19. Which optimization technique is particularly useful for reducing memory access in loops?
A) Loop unrolling
B) Strength reduction
C) Register allocation
D) Dead code elimination
Answer: A) Loop unrolling
20. Which optimization technique aims to eliminate unreachable code or unused variables during program execution?
A) Dead code elimination
B) Constant propagation
C) Loop unrolling
D) Strength reduction
Answer: A) Dead code elimination