Code:#define PR(a) printf("a = %d\t",(int) (a)); #define PRINT(a) PR(a); putchar('\n'); #define FUDGE(k) k + 3.14 main() { int x = 2; PRINT( x * FUDGE(2)); }
Code:#define PR(a) printf("a = %d\t",(int) (a)); #define PRINT(a) PR(a); putchar('\n'); #define FUDGE(k) k + 3.14 main() { int x = 2; PRINT( x * FUDGE(2)); }
Because (int)(2 * 2 + 3.14) == 7. Expand the macros and see it for yourself.
This is one reason why you will often see "extra" parentheses used to define macros, e.g.,
Code:#define FUDGE(k) ((k) + 3.14)
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Your two line program eloquently shows the wayward path leading to code hell, of using damnable defines.
For a certainty I would not want to come back in 5 years and have to read that code or update it.
Defines are not for math!
Did I mention the lack of effort?
what is the program output please explain
I think I did.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.