Consider Line 3 of the following C program: int main() { /* Line 1 */ int I,…

2005

Consider Line 3 of the following C program:

int main() {                   /* Line 1 */
  int I, N;                    /* Line 2 */
  fro (I = 0, I < N, I++);     /* Line 3 */
}

Identify the compiler's response about Line 3 while creating the object module.

  1. A.

    Both lexical and syntactic errors

  2. B.

    Only a lexical error

  3. C.

    Only syntactic errors

  4. D.

    No compilation error

Attempted by 123 students.

Show answer & explanation

Correct answer: C

Correct answer: Only syntactic errors

  • Lexical analysis: fro is a valid identifier token, and the symbols such as (, ,, ++, and ) are valid tokens. So this is not a lexical error.

  • Intended syntax analysis: In this compiler-design/PYQ framing, the line is treated as a malformed for statement: fro is not the for keyword, and the loop header uses commas where semicolons are expected. Hence the intended compiler response is syntax errors.

  • Clarification: Some C-language discussions treat fro(...) as a possible function-call expression in an older C dialect. That is a different interpretation from the intended answer key for this item.

Explore the full course: Gate Guidance By Sanchit Sir