Question Details

Consider the following C statement:


char * str1 = ”Hello”; // stmt S

char * str2 = ”Hello”; // stmt S

char * str3 = ”Hello” // stmt S


Which of the following are correct?

Options

A

S1 and S2 are lexical errors

B

S2 is lexical and S3 is semantic

C

S2 is syntax and S3 is semantic

D

S1 is lexical and S3 is syntax

Show Answer
Correct Answer
D
S1 is lexical and S3 is syntax

Solution :

The correct option is: S1 is lexical and S3 is syntax


Step-by-step Explanation:


1. Understanding Statement S1:
Let us examine the first statement:

char * str1 = ”Hello”;
Notice the quotation marks used around the string "Hello". They are curly/smart quotes (”...”) rather than the standard straight ASCII double quotes ("...") required by the C programming language.
A compiler's lexical analyzer (lexer) reads the source code character-by-character and groups them into valid tokens (such as keywords, identifiers, operators, and literals). Since the curly quote character ” is not a valid character/token in the C language character set, the lexical analyzer cannot recognize it. This results in a lexical error (also known as a scanner error or tokenization error). Thus, S1 contains a lexical error.


2. Understanding Statement S2:
The second statement is:

char * str2 = ”Hello”;
Just like S1, S2 also uses curly quotes (”...”) instead of standard straight ASCII quotes ("..."). Consequently, it would also trigger a lexical error for the same reason. However, looking at our correct option and choices, we focus on classifying S1 and S3.


3. Understanding Statement S3:
The third statement is:

char * str3 = ”Hello”
Notice that this statement does not end with a semicolon (;).
In C, a semicolon is a statement terminator required by the language's grammar rules. A syntax analyzer (parser) takes the sequence of tokens produced by the lexer and checks if they form valid grammatical structures according to the formal grammar of the language.
Because the terminating semicolon is missing at the end of the statement, the parser encounters a grammatical violation. This represents a syntax error. Thus, S3 contains a syntax error.


Conclusion:
S1 fails at the token level due to invalid characters (curly quotes), making it a lexical error.
S3 fails at the grammatical structure level due to a missing semicolon, making it a syntax error.
Therefore, the statement "S1 is lexical and S3 is syntax" is correct.

Transparent Access on Mindyard

Built for Learners & Educators Alike

Completely free for students. Educators & coaching institutes get 2 months free Pro trial to create tests.

FREE FOR STUDENTS

Practice & Learn Free for Students

Access unlimited practice questions, detailed step-by-step solutions, and exam study materials — completely free for students.

  • Unlimited mock tests & question bank practice
  • Full access to curated study library & formula notes
  • 100% free for students • No credit card required
2 MONTHS FREE TRIAL

Educators & Coaching Institutes

Create and conduct professional online assessments with AI question generation, tab proctoring, and comprehensive batch management.

  • AI question uploader & rapid test generator
  • Anti-cheating tab proctoring & performance reports
  • Full Pro access free for 60 days • No upfront commitment
Discover more resources

You may also like

Mock Tests

View All
  • GATE
  • beginner
  • 3 hours
  • civil engineering

Prepare for GATE 2026 Civil Engineering with the latest question papers, previous year papers, detailed solutions, syllabus, exam pattern, preparation tips, mock tests, and subject-wise study material. Download GATE 2026 CE question papers with solutions in PDF format and boost your preparation for top engineering institutes and PSU recruitment.

  • GATE
  • beginner
  • 3 hours
  • electronics and communication engineering

Prepare effectively for GATE 2026 Electronics & Communication Engineering (EC) with this comprehensive Question Paper with Solutions. This resource includes detailed explanations, concept-wise solutions, previous year paper analysis, and exam-oriented practice to help aspirants strengthen core subjects like Electronic Devices, Analog Circuits, Digital Circuits, Signals & Systems, Network Theory, Control Systems, Electromagnetics, Communications, and more. Perfect for revision, self-assessment, and boosting your GATE 2026 EC preparation strategy.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...
Ask your own doubt or choose a quick prompt: