Consider the following ANSI C program: int main () { Integer x; return 0; }…

2021

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?

  1. A.

    Lexical analyzer

  2. B.

    Syntax analyzer

  3. C.

    Semantic analyzer

  4. D.

    Machine dependent optimizer

Attempted by 218 students.

Show answer & explanation

Correct answer: C

Answer: Semantic analyzer.

Explanation: The lexical analyzer tokenizes identifiers like "Integer" without deciding whether they name a valid type. The syntax analyzer accepts the declaration form "Integer x;" as grammatically correct. The semantic analyzer performs symbol-table lookups and type checking; it will report an error because "Integer" is not a built-in C type and there is no typedef or declaration introducing a type named "Integer".

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir