GATE CSE 2026 Session 1 Q27: Classify errors in three C string declarations
- Compiler Design
- 1 mark
- MSQ
- No negative marking
Question
Consider the following C statements:
char *str1 = "Hello; /* Statement S1 */
char *str2 = "Hello;"; /* Statement S2 */
int *str3 = "Hello"; /* Statement S3 */Which of the following options is/are correct?
Try it: multiple select: one or more correct options
Select all correct options. No negative marking, no partial marks.
Show answer and explanation
Answer: C (official GATE 2026 final answer key)
Concept used: Lexical errors are bad tokens (e.g. an unterminated string literal); type mismatches are semantic errors.
First step: S1's string literal never closes, so the lexer cannot form a token; S2 is valid; S3 assigns a char* to an int*.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2026 Session 1 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Compiler Design PYQs
- 2026 Session 1 · Q28True statements about LL(1) parsing
- 2026 Session 1 · Q42Redundant (common) subexpressions in blocks B4 and B5 of a CFG
- 2026 Session 1 · Q53Compare two SDDs for type declarations
- 2026 Session 2 · Q35Count tokens produced by a lexer for a given string
- 2026 Session 2 · Q41Shift-reduce conflicts in the LR(0) table of a grammar
- 2026 Session 2 · Q45Live variables at the exit of each block in a loop CFG