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?
Correct Answer :
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.
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 (;).
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.
Access expert-curated educational resources and study materials—completely free.
Create, conduct, and manage professional online assessments with Mindyard. Perfect for teachers and institutes.
Copyright © 2026 Mindyard. All Rights Reserved.