Computer Sciences > GATE 2026 SET-1 > Lexical and Syntax Analysis
Consider the following statements:

Char  * Str1 = "Hello ;    /* Statement S1 */
Char  * Str2 = "Hello ;";  /* Statement S2 */
int   * Str3 = "Hello" ;  /* Statement S3 */

Which of the following is/are correct?
A
S2 has lexical error and S3 has Syntactic error.
B
S1 has lexical error and S3 has Semantic error.
C
S1 has Syntactic error and S2 has Syntactic error.
D
S1 has Syntactic error and S3 has Semantic error.

Correct : b

Option B is the correct answer.
Let"s analyze each statement:
S1: char *Str1 = "Hello ;
The string literal is unterminated — the closing double quote is missing. The lexer cannot form a valid string token, making this a lexical error.
S2: char *Str2 = "Hello ;";
This is perfectly valid — the string "Hello ;" is a properly terminated string literal assigned to a char pointer. No error.
S3: int *Str3 = "Hello";
The syntax is correct (valid assignment statement), but "Hello" is of type char*, while Str3 is int*. Assigning a char pointer to an int pointer is a semantic (type) error.
Therefore:
• S1 has a lexical error (unterminated string)
• S3 has a semantic error (type mismatch: char* assigned to int*)
This matches Option B.

Similar Questions

A palindrome is a word that reads the same forwards and backwards. In a game of words, a player has the following two plates painted with letters. From...
#1 MCQ
Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64
#4 MCQ
Choose the word that is opposite in meaning to the word “coherent”.
#5 MCQ

Related Topics

GATE CS 2026 GATE CS 2026 Set-1 Q17 Lexical Error Semantic Error Syntactic Error Unterminated String Literal Type Mismatch char pointer int pointer Compiler Design GATE Lexical Analysis GATE GATE CS 2026 Solved Compiler Errors C Program

Unique Visitor Count

Total Unique Visitors

Loading......