58 58 votes The number of tokens in the following C statement isprintf("i=%d, &i=%x", i, &i);$3$$26$$10$$21$ Related Questions :ISRO CSE 2020 | Question: 13 Compiler Design gatecse-2000 compiler-design lexical-analysis easy isro2015 + – Kathleen 48.1k views answer comment Share Follow Print See all 6 Comments 6 6 Comments reply Show 3 previous comments vishalshrm539 commented Sep 22, 2018 reply Follow flag WhiteSpaces will be removed by the lexical analyser from the source code, this is one of the jobs of LA. 4 4 replyShare chetan-naik commented Dec 7, 2024 reply Follow flag Note to self: Token is the atomic thing recognized by the lexical analyser like keywords, strings, operators, etc.Lexeme is the sequence of the input character that can be associated with the token. Eg. int is the lexeme of the keyword token.We use pattern matching (Regular language) to identify the token class of a lexeme.Whitespace is not token in C lang. 2 2 replyShare Deepak Poonia commented Nov 20, 2025 reply Follow flag Detailed Video Explanation: https://www.youtube.com/watch?v=f-yJP8KTNrk&t=6466s 2 2 replyShare Please log in or register to add a comment.
Best answer 84 84 votes answer - C Tokens are: printf ( "i=%d, &i=%x" , i , & i ) ; ankitrokdeonsns answered Nov 23, 2014 • edited Dec 4, 2017 by kenzou ankitrokdeonsns comment Share Follow See all 8 Comments 8 8 Comments reply Show 5 previous comments tusharp commented Nov 22, 2018 reply Follow flag There is line of declaration and line of usage column in symbol table. There just the line number where occurrence of i is used/declared can be given. 1 1 replyShare tusharp commented Nov 22, 2018 reply Follow flag http://arantxa.ii.uam.es/~modonnel/Compilers/04_SymbolTablesI.pdf 0 0 replyShare Deepak Poonia commented Nov 20, 2025 reply Follow flag NOTE: In the above answer, from $1$ to $10,$ these are Lexemes, not Tokens. For each lexeme, a token is generated by the lexical analyser. So, number of tokens will be $10$.Lexeme: The piece of the original program from which we make the token is called a Lexeme.A lexeme is a sequence of characters in the source program that matches the pattern for a token and is identified by the lexical analyzer as an instance of that token.As the first phase of a compiler, the main task of the lexical analyzer is to read the input characters of the source program, group them into lexemes, and produce as output a sequence of tokens for each lexeme in the source program.Detailed Video Explanation: https://www.youtube.com/watch?v=f-yJP8KTNrk&t=6466s 7 7 replyShare Please log in or register to add a comment.
13 13 votes printf("i=%d,&i=%x",i&i); it has 9 token but option are not matching the same question came in gate 2001 printf("i=%d,&i=%x",i,&i); with this statement it has 10 token 1.printf 2.(3."i=%d,&i=%x"4.,5.i6.,7.&8.i9.)10.; Umang Raman answered Oct 11, 2015 Umang Raman comment Share Follow See all 6 Comments 6 6 Comments reply abby murali commented Oct 12, 2015 reply Follow flag Is the string inside the print statement considered as a single token (token no. 3)...? 0 0 replyShare Umang Raman commented Oct 12, 2015 reply Follow flag yes! 0 0 replyShare abby murali commented Oct 13, 2015 reply Follow flag Thanks for the reply... Actually my doubt is about the quotes (" " ) shouldn't we count that also...? 0 0 replyShare Umang Raman commented Oct 13, 2015 reply Follow flag C tokens are of six types. They are, Keywords (int, while,etc), Identifiers ( main, total,etc), Constants ( 10, 20), Strings ( “total”, “hello”), Special symbols ( (,), {,} etc), Operators ( +, /,-,*,etc) 32 32 replyShare neethu_seb commented Dec 2, 2019 reply Follow flag printf("i=%d,&i=%x",i&i); --- comma is missing, that is why geetting 9 as count. 0 0 replyShare Arpan_Ghosh commented Sep 22, 2024 reply Follow flag The question asked about the number of tokens in printf("i=%d,&i=%x",i,&i); 1. printf 2. ( 3. "i=%d,&i=%x" 4. , 5. i 6. , 7. & 8. i 9. ) 10. ; Therefore, the number of tokens is 10. 0 0 replyShare Please log in or register to add a comment.
12 12 votes print = token1 ( = token2 "i=%d%x" = token3 ////anything inside " " is considered as 1 token , = token4 i = token5 , = token6 & = token7 i = token8 ) = token9 ; = token10 so total 10 tokens Tauhin Gangwar answered Jun 7, 2016 Tauhin Gangwar comment Share Follow 0 reply Please log in or register to add a comment.
5 5 votes 1.printf 2.( 3."i=%d, &i=%x" 4., 5.i 6., 7.& 8.i 9.) 10.; option C Umang Raman answered Nov 2, 2015 Umang Raman comment Share Follow See all 7 Comments 7 7 Comments reply Show 4 previous comments Arjun commented Jun 4, 2016 reply Follow flag it is an operator- returns the address of operand. 3 3 replyShare Ram Sharma1 commented Jun 18, 2016 reply Follow flag Okey 0 0 replyShare rajatmyname commented Sep 4, 2016 reply Follow flag Arjun Sir, In the complete reference it has discussed three types of reference-VARIABLE,NUMBER and DELIMITER.Is it correct or the above types of tokens is right? 0 0 replyShare Please log in or register to add a comment.
2 2 votes if it is i++ in place of &i then answer will be 10 ?? rajan answered Nov 16, 2016 rajan comment Share Follow See 1 comment 1 1 comment reply saurabh rai commented Nov 16, 2016 reply Follow flag yes bcoz both(i++ and &i ) have 2 tokens. 5 5 replyShare Please log in or register to add a comment.
1 1 vote Number of tokens(i.e valid lexemes that matches with their pattern ) are 1)printf 2). ( 3)"i=%d, &i=%x" 4.) , 5) i 6) , 7) & 8) i 9) ) 10) ; Hence ,total no of tokens =10 ,Answer C is correct. Deepak Gupta 1 answered Mar 24, 2017 Deepak Gupta 1 comment Share Follow 0 reply Please log in or register to add a comment.