3,354 views
14 votes
14 votes

Consider the following C program:
 

int main (void)
{
    in/*this is an example*/z;
    
    double/*is it an error?*/y;
    
    print( “This is simple” );
    
    return 0;
}

- How many Different tokens are there in the above code.

2 Answers

Best answer
22 votes
22 votes
int main ( void )
{
    in z ;
    
    double y ;
    
    print( “This is simple” );
    
    return 0 ;
}

All Colored ones are different Tokens = 16

Types of tokens-  

keywords - int, void , double, return.

Identifiers - main , in, z, y, print.

Strings     - “This is simple”.

Constant  - 0.

Special- symbols / Delimiter / Punctuator /  - ( , ), ; , { , } , comma.

NOTE:

 ( 6 types of  c tokens )

edited by
0 votes
0 votes
"int","main","(","void",")"-5 tokens

"{"-1 token

"inz",";"-2 tokens

"double","y",";"-3 tokens

"printf","(","String literal",")",";"-5 tokens

"return","0",";"- 3 tokens

"}"- 1 token

Total 20 tokens

int,void-keyword

"inz","y"-identifier

";"-delimeter
edited by

Related questions

2 votes
2 votes
5 answers
2
Mizuki asked Nov 11, 2018
1,833 views
What it the number of tokens in the following line?printf("%d numbers.", &x);
1 votes
1 votes
2 answers
3
Lovejeet Singh asked Nov 7, 2018
1,185 views
How will the compiler detect whether "if" is a keyword or an identifier?Please tell me the concept behind this.