Question:medium

Consider the following ANSI C program: 

int main() { 
    Integer x; 
    return 0; 
}

Which one of the following phases in a seven-phase C compiler will throw an error?

Show Hint

Identifiers may pass lexical and syntax checks but still fail semantic analysis if their meanings are invalid in the language.
Updated On: Feb 3, 2026
  • Lexical analyzer
  • Syntax analyzer
  • Semantic analyzer
  • Machine dependent optimizer
Show Solution

The Correct Option is C

Solution and Explanation

In the given ANSI C program:

int main() { 
    Integer x; 
    return 0; 
}

The program attempts to declare a variable x with the type Integer. However, this is not a valid data type in C; the correct type is int. Let us analyze which phase of the compiler will catch this error.

  1. Lexical Analyzer: This phase performs tokenization, breaking down the code into valid tokens like keywords, identifiers, operators, etc. Since Integer can be considered a valid identifier token, it will not be flagged as an error here.
  2. Syntax Analyzer: This phase checks the syntactical structure of the code against grammar rules. The syntax in this code is technically correct, so this phase will not trigger an error.
  3. Semantic Analyzer: This phase checks for semantic consistency, including type checking and ensuring that all identifiers are declared with valid data types. Here, the semantic analyzer will identify that Integer is not a valid type and will report an error.
  4. Machine Dependent Optimizer: This phase works on optimizing the generated machine code for the target architecture. It typically doesn't catch errors related to type declaration issues in source code.

Thus, the correct option is the Semantic analyzer, as it catches the type mismatch or undeclared type issues typically involved in semantic analysis.

Was this answer helpful?
0