Intermediate Code Generation MCQs

1. What is the primary purpose of intermediate code generation in a compiler?

A) To perform lexical analysis
B) To generate machine code directly
C) To translate the source code into an intermediate representation that is independent of the target machine
D) To optimize the source code for execution

Answer: C) To translate the source code into an intermediate representation that is independent of the target machine


2. Which of the following is NOT a type of intermediate code representation?

A) Three-address code
B) Abstract syntax tree
C) Assembly code
D) Bytecode

Answer: C) Assembly code


3. What is a primary advantage of using intermediate code during compilation?

A) It makes the compiler faster
B) It simplifies machine code generation by decoupling the target architecture
C) It reduces the size of the source code
D) It helps in performing more complex lexical analysis

Answer: B) It simplifies machine code generation by decoupling the target architecture


4. Which of the following statements is true regarding intermediate code generation?

A) It generates the final machine code directly
B) It is only used in interpreting languages, not in compilers
C) It generates an intermediate form that can be optimized before final code generation
D) It is only used in JIT (Just-in-Time) compilers

Answer: C) It generates an intermediate form that can be optimized before final code generation


5. In which phase of the compiler does the intermediate code generation take place?

A) Lexical analysis
B) Syntax analysis
C) Semantic analysis
D) Code generation

Answer: D) Code generation


6. Which of the following is an example of an intermediate code representation?

A) Machine code
B) Three-address code
C) Syntax tree
D) Source code

Answer: B) Three-address code


7. What does three-address code consist of?

A) A series of high-level language instructions
B) A list of memory addresses
C) Instructions that use at most three addresses (operands) for each instruction
D) Low-level machine instructions

Answer: C) Instructions that use at most three addresses (operands) for each instruction


8. Which of the following is a characteristic of an intermediate code?

A) It is independent of any specific machine architecture
B) It cannot be optimized
C) It must always be in assembly language
D) It is used only for debugging purposes

Answer: A) It is independent of any specific machine architecture


9. Why is intermediate code useful in a compiler?

A) It speeds up the execution of the program
B) It allows the compiler to perform target-specific optimizations
C) It helps the programmer write code more efficiently
D) It eliminates the need for syntax checking

Answer: B) It allows the compiler to perform target-specific optimizations


10. Which of the following is the main advantage of generating intermediate code for optimization purposes?

A) It ensures that the final code will run faster
B) It makes the code platform-independent
C) It allows for machine-specific optimizations
D) It ensures syntax errors are avoided

Answer: C) It allows for machine-specific optimizations


11. Which of the following is an example of an intermediate code generator in real-world compilers?

A) LLVM IR
B) Assembler
C) Linker
D) Preprocessor

Answer: A) LLVM IR


12. In the context of intermediate code generation, what is the purpose of generating a “control flow graph”?

A) To represent the sequence of statements and conditional branches in a program
B) To generate machine-level instructions
C) To check for syntax errors
D) To represent the structure of the program’s source code

Answer: A) To represent the sequence of statements and conditional branches in a program


13. Which of the following is true about the intermediate code in a compiler?

A) It is the final output of the compilation process
B) It is generated by the syntax analyzer
C) It helps decouple optimization from machine code generation
D) It is always platform-specific

Answer: C) It helps decouple optimization from machine code generation


14. What is one benefit of using intermediate code for cross-platform compilation?

A) The compiler generates machine code for each target architecture
B) The intermediate code can be further translated into machine code for different target platforms
C) The code is always executed on a virtual machine
D) The source code becomes platform-independent

Answer: B) The intermediate code can be further translated into machine code for different target platforms


15. What is a key feature of an intermediate code like three-address code?

A) It uses four or more operands in each instruction
B) It is easy for humans to understand
C) It provides a higher level of abstraction from machine code
D) It directly translates into machine code

Answer: C) It provides a higher level of abstraction from machine code

Leave a Reply

Your email address will not be published. Required fields are marked *