Thread for the C/C++ Beginners and Programmers!

ok,lets see if you can figure the output of this out.(Feeling Bored :p)

Code:
#define SQ(x) x*x
 main()
 {
  int a=SQ(2+1);
  printf("%d",a);
 }
 
You do love macros don't you ? :p

Well the output is 5 since the macro expansion will be as follows:
2+1*1+2

It would have been 9 had you defined your macro as #define SQ(x) (x)*(x)
 
Ritwik said:
You do love macros don't you ? :p

Well the output is 5 since the macro expansion will be as follows:
2+1*1+2

It would have been 9 had you defined your micro as #define SQ(x) (x)*(x)

Correct.Sorry that I was late on replying this,been a bit busy for the past couple of days.
 

Users who are viewing this thread

Top