in Compiler Design edited by
2,632 views
0 votes
0 votes

Identify the total number of tokens in the given statement

printf("A%B=",&i);
  1. $7$
  2. $8$
  3. $9$
  4. $13$
in Compiler Design edited by
by
2.6k views

4 Answers

3 votes
3 votes
"A%B=" is counted as one so total tokens are 8

1. printf

2. (

3. "A%B="

4. ,

5. &

6. i

7. )

8. ;

2 Comments

There’s no comma in the given statement.
0
0
NO sir
0
0
1 vote
1 vote

$\textrm{Total number of token is 7 here.}$

  1. $printf$
  2. $($
  3. $\textrm{”A%B”}$
  4. $\textrm{&}$
  5. $i$
  6. $)$
  7. $;$

$\textrm{Option A }$

1 comment

Why haven’t you considered comma in this question ?
0
0
0 votes
0 votes

the tokens are:

  1. printf - a function that prints output to the console
  2. ( - left parenthesis
  3. "A%B=" - a string literal
  4. , - a comma
  5. & - the address-of operator
  6. i - a variable
  7. ) - right parenthesis

The semicolon at the end of the statement is not a token. It is a statement terminator that indicates the end of the statement in C-style languages.

0 votes
0 votes

I See that people are merely justifying the answers key with 7 tokens, but the real answer is going to be 8 tokens.

Someone missed comma, someone says semicolon is not included etc; ignore them and see the official grammar of C  - both $comma$ and $semicolon$ are valid tokens.

Here is breakdown for all 8 tokens in the statement :

Tokens and Their Values
Token CategoryToken NumberToken Value
identifier1'printf'
l_paren2'('
string_literal3'"A%B="'
comma4','
amp5'&'
identifier6'i'
r_paren7')'
semi8';'
Answer:

Related questions