• edited by
8,416 views
6 6 votes

Consider the following C program :
```
# include
main()
I
int }x=10,y=12
char * a;
a=&a;
x = 1xab;
printf ("%d %d", x, * a);
}
```

Which of the following type of error (earliest phase) is identified during compilation of the program ?
a. Lexical error
b. Syntax error
c. $\AA$ Semantic error
d. None of these
Attempt
Incorrect
Your Ans.
Correct Ans.
a

3 Answers

Best answer
22 22 votes
1xab - is not a valid token in C (as variable names cannot start with a digit and numbers cannot have a letter other than 'x' (for hex) or 'l' (for long) and also not a valid keyword) and hence lexical error. It could have been x1ab, _x1ab etc. both would have given a semantic error for variable not defined.
• selected by
3 3 votes

It is a lexical error at earliest as we can see that the token "1xab" will be treated as an identifier ..But we know as per standard naming convention in C language , the variable name cannot begin with "1" ..

So it will be an invalid token..Hence the error concerned will be lexical error at the earliest..

Hence A) is correct answer..

0 0 votes
Lexical analyser scan the program and generate token store into symbol table and return token id.
Token may be
Keyword
Identifier(function or variable)
Operators
Special symbols.
So 1xba not any things
So it produces Lexical error
Position:
Show:

Related questions

1 1 vote
1 1 answer
648
648 views
vaishali jhalani asked Nov 23, 2016
648 views
Consider the following C program : # includemain()Iint }x=10,y=12char * a;a=&x;x=1xab;printf("%d %d",x, * a);I Which of the following type of error (earliest phase) i...
0 0 votes
1 1 answer
2.6k
2.6k views
Mohit Aggarwal asked Dec 1, 2021
2,600 views
what is the difference between lexical error and syntax error?
6 6 votes
7 7 answers
5.4k
5.4k views
Na462 asked Oct 5, 2018
5,407 views
11 11 votes
6 6 answers
12.4k
12.4k views
Shubhanshu asked Jan 31, 2018
12,424 views
int main() { int 1a, b; Printf("\nGate 2018"); Printf("%d",x); }How many types of error are there in this code?