4
#define power(a) #a
  int main()
  {
    printf("%d",*power(432));
     return 0;
  }

can anyone explain the o/p??
the o/p is

52

akash
  • 1,801
  • 7
  • 24
  • 42
  • 3
    What do you think it does? Have you made any effort understanding this code? It's trivial. –  Mar 02 '13 at 14:13
  • i m not able to understand what '*' does?? – akash Mar 02 '13 at 14:17
  • 2
    In that case you're in the most serious need of reading a basic C language tutorial. It's used for pointer dereferencing. –  Mar 02 '13 at 14:17
  • 3
    @akash in `power(432)` => `"432"` and `*"432"` => `"432"[0]` => `'4'` and because `%d` ascii value printed. Remember we do `char* ch = "432"` that means type of a string is `"432"` is `char*` so we can index using `[]`. as we can do `ch[]` Your **macro** convert macro function argument to string. because single `#` operator. – Grijesh Chauhan Mar 02 '13 at 14:21

2 Answers2

12

It is equivalent to:

printf("%d",*"432");

which is equivalent to:

printf("%d", '4');

and the ASCII value of '4' is 52.

ouah
  • 142,963
  • 15
  • 272
  • 331
0
#define power(a) #a   //# is a stringization operation in macro
  int main()
  {
    printf("%d",*power(432));
     return 0;
  }

Hence after calling power(432), macro will return it "432" and applying * on it gives first value which is nothing but 52 (48 + 4) for '4' .