edited by
21,837 views
80 votes
80 votes

Consider line number $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 this line while creating the object-module:

  1. No compilation error
  2. Only a lexical error
  3. Only syntactic errors
  4. Both lexical and syntactic errors
edited by

9 Answers

0 votes
0 votes

loop statement is written as fro (I=0, I<N, I++);. This contains both lexical and syntactic errors:

  1. Lexical error: The keyword "for" is misspelled as "fro", which is not recognized by the C compiler. This is a lexical error because it involves incorrect spelling or misuse of language elements.

  2. Syntactic error: The loop statement has three expressions enclosed in parentheses, separated by commas. However, the correct syntax requires semicolons (;) instead of commas (,) to separate the expressions. So the correct form should be for (I=0; I<N; I++).

Therefore, the compiler will report both lexical and syntactic errors in line 3 of the code. The correct option would be D. Both lexical and syntactic errors.

Answer:

Related questions

31 votes
31 votes
2 answers
9
go_editor asked Nov 27, 2016
11,619 views
Consider the following expression grammar. The semantic rules for expression evaluation are stated next to each grammar production.$$\begin{array}{l|l} E\rightarrow numbe...
24 votes
24 votes
2 answers
10
34 votes
34 votes
5 answers
11
0 votes
0 votes
1 answer
12
go_editor asked Mar 26, 2020
1,041 views
Which of the statements related to Compilers is wrong ?Lexical analysis is breaking the input into tokensSyntax analysis is for parsing the phraseSyntax analysis is for a...