Introduction to Compilers MCQs

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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

Leave a Comment

All copyrights Reserved by MCQsAnswers.com - Powered By T4Tutorials