GATE CS 2026 Set 1 | Question 27
Compiler Design › Basics & Lexical · MSQ · 1 mark · Answer: C
- Question 27Compiler Designmsq1 markConsider the following C statements:
Which of the following options is/are correct?char *str1 = "Hello; /* Statement S1 */ char *str2 = "Hello;"; /* Statement S2 */ int *str3 = "Hello"; /* Statement S3 */- A.S1 and S2 have syntactic errors
- B.S2 has a lexical error and S3 has a syntactic error
- C.S1 has a lexical error and S3 has a semantic error✓
- D.S1 has a syntactic error and S3 has a semantic error
Answer: C
Solution
Answer: C • S1: the string literal is never closed, so the lexer cannot form a valid token. That is a lexical error. • S2:"Hello;"is a valid string, so there is no error. • S3: the tokens and syntax are fine, but achar*is assigned to anint*. That type mismatch is caught during type checking, so it is a semantic error. - A.
More GATE PYQ on Basics & Lexical
All GATE CS Compiler Design PYQ →Attempt GATE CS 2026 Set 1 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →