The GATE Grind

GATE 2026 CS (CS1) – Question 27

Compiler Design · Lexical Analysis · 1 mark · Multiple select

Consider the following C statements:
`char *str1 = "Hello; /* Statement S1 */`
`char *str2 = "Hello;"; /* Statement S2 */`
`int *str3 = "Hello"; /* Statement S3 */`
Which of the following statements is/are true?

  1. S1 and S2 have syntactic errors
  2. S2 has a lexical error and S3 has a syntactic error
  3. S1 has a lexical error and S3 has a semantic error
  4. S1 has a syntactic error and S3 has a semantic error

Practise this question in The GATE Grind →

Show answer and explanation

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

Explanation

Therefore, option (C) correctly identifies S1 as having a lexical error and S3 as having a semantic error.