Skip to content
Official PYQ · 2000

GATE CS 2000 Q1.18 — Lexical Analysis

Explain with AI

The number of tokens in the following C statement is

printf("i=%d, &i=%x", i, &i);
Choose one option
View worked solution

Answer: C

A token is the smallest individual unit in a source program that is meaningful to the compiler. The lexical analyzer scans the input character-by-character and groups them into tokens.

Let's break down the given C statement into its constituent tokens:

Token NumberTokenType
1printfIdentifier
2(Separator / Parenthesis
3"i=%d, &i=%x"String Literal
4,Separator / Comma
5iIdentifier
6,Separator / Comma
7&Operator (Address-of)
8iIdentifier
9)Separator / Parenthesis
10;Punctuation / Semicolon

Note that the entire string "i=%d, &i=%x" is treated as a single string literal token by the lexical analyzer.

Therefore, the total number of tokens is 10.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Lexical Analysis questions