Skip to main content

10 questions related to compiler phases

10 questions related to compiler phases, suitable for UGC NET, SET, and GATE exams, along with their descriptions:


1. Which phase of the compiler is responsible for removing comments and white spaces?

A) Syntax Analysis
B) Lexical Analysis
C) Semantic Analysis
D) Code Optimization

Explanation:
The Lexical Analysis phase scans the input source code and removes comments and white spaces while converting it into tokens.

Answer: B) Lexical Analysis


2. What is the primary purpose of syntax analysis in a compiler?

A) Checking grammatical structure
B) Checking for type mismatches
C) Generating intermediate code
D) Allocating memory

Explanation:
Syntax Analysis (Parsing) ensures that the program follows the correct grammatical structure as per the language’s rules.

Answer: A) Checking grammatical structure


3. In which compiler phase is a syntax tree generated?

A) Lexical Analysis
B) Syntax Analysis
C) Semantic Analysis
D) Code Generation

Explanation:
During Syntax Analysis (Parsing), a syntax tree (parse tree) is constructed to represent the program’s structure.

Answer: B) Syntax Analysis


4. Which phase of a compiler is responsible for checking the correct use of identifiers and types?

A) Syntax Analysis
B) Lexical Analysis
C) Semantic Analysis
D) Code Optimization

Explanation:
Semantic Analysis checks for type mismatches, undeclared variables, and correct identifier usage in the program.

Answer: C) Semantic Analysis


5. Which of the following phases generates an intermediate representation of the source code?

A) Lexical Analysis
B) Syntax Analysis
C) Intermediate Code Generation
D) Code Optimization

Explanation:
Intermediate Code Generation translates source code into an intermediate representation (IR), which is machine-independent.

Answer: C) Intermediate Code Generation


6. Which compiler phase is responsible for register allocation?

A) Lexical Analysis
B) Syntax Analysis
C) Code Optimization
D) Code Generation

Explanation:
Code Optimization and Code Generation handle register allocation to improve efficiency and execution speed.

Answer: C) Code Optimization


7. Peephole optimization is applied in which compiler phase?

A) Lexical Analysis
B) Syntax Analysis
C) Semantic Analysis
D) Code Optimization

Explanation:
Peephole Optimization is a local optimization technique applied in the Code Optimization phase to improve performance.

Answer: D) Code Optimization


8. Which phase of the compiler converts intermediate representation into machine code?

A) Syntax Analysis
B) Code Optimization
C) Code Generation
D) Lexical Analysis

Explanation:
Code Generation translates the intermediate code into machine-dependent assembly or machine code.

Answer: C) Code Generation


9. Which of the following is NOT an intermediate representation format used in compilers?

A) Abstract Syntax Tree (AST)
B) Three-Address Code (TAC)
C) Symbol Table
D) Bytecode

Explanation:
The symbol table is not an intermediate representation format; it stores identifier information during compilation.

Answer: C) Symbol Table


10. The process of mapping variables and functions to memory locations is handled by which phase?

A) Code Optimization
B) Symbol Table Management
C) Code Generation
D) Semantic Analysis

Explanation:
Symbol Table Management is responsible for mapping variables, functions, and their memory locations.

Answer: B) Symbol Table Management

Comments

Popular posts from this blog

Top 5 Safe Chat Apps for Kids with Parental Controls

Now a days kids are growing up with technology at their fingertips. While communication apps help children stay connected with family and friends, safety remains a top concern for parents. Unregulated platforms can expose children to inappropriate content, online predators, and cyberbullying. That’s why choosing a kid-friendly chat app with parental controls is essential. To help parents find the best options, we’ve compiled a list of the top five safest chat apps for kids that offer safe and controlled environment. 1. Messenger Kids (By Meta) Best for: Safe video calls and text messaging with parental supervision Features: Parents approve all contacts No ads or in-app purchases Fun filters, stickers, and games Monitored messaging and activity reports Why It’s Safe: Messenger Kids is designed for children under 13 and requires parental approval for every contact. Parents can monitor chats and control screen time through the Parent Dashboard. Download Messenger Kids 2...

10 Distance Vector and Link-State Routing MCQ

  10 multiple-choice questions  on  Distance Vector and Link-State Routing with explanations, useful for  UGC NET, SET, GATE, ISRO, and other competitive exams . Question 1: Basic Concept of Distance Vector Routing Q1: In a distance vector routing protocol, how do routers share routing information? A) By flooding the entire network with routing updates B) By periodically exchanging routing tables with their immediate neighbors C) By using a link-state database to determine the shortest path D) By dynamically updating paths based on link failure reports Answer: B) By periodically exchanging routing tables with their immediate neighbors Explanation: In Distance Vector Routing, routers share their routing tables with neighbors at regular intervals, leading to a simple but slow convergence mechanism. Question 2: Example of Distance Vector Routing Protocol Q2: Which of the following is an example of a Distance Vector routing protocol? A) OSPF ...

10 Routing Protocol MCQ

10 multiple-choice questions on Routing protocol s  with explanations, useful for UGC NET, SET, GATE, ISRO, and other competitive exams . Question 1: Purpose of Routing Protocols Q1: What is the primary purpose of a routing protocol? A) To assign IP addresses to devices B) To determine the best path for data packets to reach their destination C) To encrypt data during transmission D) To physically connect different networks Answer: B) To determine the best path for data packets to reach their destination Explanation: Routing protocols help routers determine the most efficient path for data transmission across a network, ensuring fast and reliable communication. Question 2: Classification of Routing Protocols Q2: Routing protocols can be broadly classified into which two main categories? A) TCP and UDP B) Distance Vector and Link-State C) IPv4 and IPv6 D) Static and Dynamic Answer: B) Distance Vector and Link-State Explanation: Routing prot...