- What is the primary purpose of a compiler?
a) To execute programs directly
b) To translate high-level programming languages to machine code
c) To perform memory management
d) To compile programs for runtime environmentsAnswer: b) To translate high-level programming languages to machine code - Which of the following is NOT a type of compiler?
a) Single-pass compiler
b) Multi-pass compiler
c) Just-in-time compiler
d) Machine code compilerAnswer: d) Machine code compiler - What is the main difference between a compiler and an interpreter?
a) A compiler translates code line by line, while an interpreter translates the entire program at once
b) A compiler translates the entire program at once, while an interpreter translates code line by line
c) A compiler is faster than an interpreter
d) There is no differenceAnswer: b) A compiler translates the entire program at once, while an interpreter translates code line by line - Which of the following is the first phase of compilation?
a) Semantic analysis
b) Code optimization
c) Lexical analysis
d) Code generationAnswer: c) Lexical analysis - What does a multi-pass compiler do?
a) Translates the entire program in a single pass
b) Analyzes the program in multiple stages to optimize it
c) Runs the program directly on the hardware
d) Only checks for syntax errorsAnswer: b) Analyzes the program in multiple stages to optimize it - Which of the following is true about a Just-in-time (JIT) compiler?
a) It compiles code before execution and stores it in memory
b) It compiles code at runtime to optimize execution speed
c) It works in a single pass
d) It translates source code into machine code without executionAnswer: b) It compiles code at runtime to optimize execution speed - What is the primary difference between an assembler and a compiler?
a) An assembler translates high-level language to machine code, while a compiler translates assembly language to machine code
b) An assembler translates assembly language to machine code, while a compiler translates high-level language to machine code
c) Both are the same
d) A compiler only processes one instruction at a timeAnswer: b) An assembler translates assembly language to machine code, while a compiler translates high-level language to machine code - What is a typical output of the compilation process?
a) An interpreted script
b) A binary file or executable
c) A source code file
d) A debug fileAnswer: b) A binary file or executable - Which phase of compilation is responsible for checking the syntax of the program?
a) Semantic analysis
b) Syntax analysis
c) Lexical analysis
d) Code generationAnswer: b) Syntax analysis - What is the role of a lexical analyzer in the compilation process?
a) To translate the program into machine code
b) To check the program’s syntax and semantics
c) To convert high-level programming language constructs into tokens
d) To generate intermediate code
Answer: c) To convert high-level programming language constructs into tokens