-5

for the following code can we consider '#define' as token?

#define int char 
 main(){
   int i=65;               // i is initialized  
   printf("sizeof(i)=%d",sizeof(i)); 
}
Dash_25
  • 1
  • 1
  • 6
  • I'm voting to close this question as off-topic because homework should be attempted – Mitch Wheat Jan 11 '17 at 05:03
  • sorry, but this is not a homework question. – Dash_25 Jan 11 '17 at 05:09
  • it is 2 preprocessing tokens, `#` and `define` – M.M Jan 11 '17 at 05:10
  • 3
    Then why did it originally say "*For the following ‘C’ fragment, identify and list the lexemes that make up tokens.*"? – melpomene Jan 11 '17 at 05:10
  • 2
    best idea ever!: "#define int char " ! – Mitch Wheat Jan 11 '17 at 05:10
  • first of all it is question from previous year paper and after 2 hours my exam will be taken.i am only concerned about preprocessor directives else part i can handle. if anyone knows the anser then plz tell me. – Dash_25 Jan 11 '17 at 05:15
  • 1
    In the future, I recommend learning to use your favorite search engine for questions that will obviously have publicly available answers instead of asking other people to find them for you. Who knows, in the process you might learn something in addition to your one narrow question. – Carey Gregory Jan 11 '17 at 05:22
  • @CareyGregory i will remember this for next time,thank you sir. – Dash_25 Jan 11 '17 at 05:24

1 Answers1

1

The ISO C standard explicitly calls out what tokens exist, for example, in c11 6.4:

token:
    keyword
    identifier
    constant
    string-literal
    punctuator
preprocessing-token:
    header-name
    identifier
    pp-number
    character-constant
    string-literal
    punctuator
    each non-white-space character that cannot be one of the above

So, no, #define is not a token, it's two pre-processing tokens, # and the define identifier.

It's an identifier as per 6.4.2.1 where it's defined as basically [_A-Za-z][_A-Za-z0-9]*.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953