GateAI
Lexical Analysis

GATE CSE 2026 Set 1 · Q27

MSQ1 markEasy

Time

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?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: C) S1 has a lexical error and S3 has a semantic error

Lexical Analysis

Let us analyze the three statements:

  1. Statement S1 (char *str1 = "Hello;):

    • The string literal is missing the closing double quote ".

    • Tokenization fails to form a valid string token, which is detected during the lexical analysis phase as an unclosed string literal (a lexical error).

  2. Statement S2 (char *str2 = "Hello;";):

    • This is a completely valid declaration and initialization of a string literal in C. It contains no error.

  3. Statement S3 (int *str3 = "Hello";):

    • Syntactically, this is valid (a pointer variable is initialized with an expression).

    • However, the string literal "Hello" produces a pointer to char (char *), which is being assigned to a pointer to int (int *) without a cast. This represents a type mismatch, which is detected during the semantic analysis phase (a semantic error).

Therefore, S1 has a lexical error and S3 has a semantic error, making (C) the correct option.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Lexical Analysis previous year question is Q27 of the GATE CSE 2026 Set 1 paper. Find more GATE CSE PYQs on Lexical Analysis in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Lexical Analysis PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Lexical Analysis in GATE CSE

Lexical Analysis has 7 GATE CSE PYQs across 6 papers from 2011 to 2026. This is the only 1-mark MSQ among them, and it is the only one in GATE CSE 2026 Set 1.

How GATE tests Lexical Analysis

More from GATE CSE 2026 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2026 Set 1 · Q27 · MSQ

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?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.