Question

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?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2021 answer key

Solution

Trace compiler phases for the statement 'Integer x;' when Integer is not defined.

The program contains the statement Integer x; inside main().

  1. Lexical Analysis: Integer matches the pattern of a valid identifier token, and x is another valid identifier. Both are recognized without error.
  1. Syntax Analysis: The grammar of C includes productions of the form <type_name> <identifier>; (or typedef-name followed by variable name). The syntax analyzer builds a valid parse tree according to the context-free grammar rules.
  1. Semantic Analysis: The compiler checks type declarations and symbol table entries. Because Integer has not been defined via typedef or as a primitive type, type resolution fails. The semantic analyzer reports an undeclared type error.
Final answer

C

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
Question
13 of 65, printed as CS Q.3
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.