Sep 14, 2003 #1 Sac123 Programmer Jul 24, 2003 3 IN #define MAX(a,b) (a>b?a:b) void main(void) { int a = 3, b=4; printf("%d %d %d\n",a,b,MAX(a++,b++)); } I expected the answer for this as 4 5 4 but answer i got is 4 6 5 Can anyone explain me why is this so...
#define MAX(a,b) (a>b?a:b) void main(void) { int a = 3, b=4; printf("%d %d %d\n",a,b,MAX(a++,b++)); } I expected the answer for this as 4 5 4 but answer i got is 4 6 5 Can anyone explain me why is this so...
Sep 14, 2003 #2 Cagliostro Programmer Sep 13, 2000 4,226 GB at the first is executed (a++ > b++ ? a : b) after that is passed to printf; Ion Filipski ICQ: 95034075 AIM: IonFilipski filipski@excite.com Upvote 0 Downvote
at the first is executed (a++ > b++ ? a : b) after that is passed to printf; Ion Filipski ICQ: 95034075 AIM: IonFilipski filipski@excite.com
Sep 14, 2003 Thread starter #3 Sac123 Programmer Jul 24, 2003 3 IN but according to ur explaination it should print 4 5 4. can you plz elaborate why b is getting incremented twice Upvote 0 Downvote
but according to ur explaination it should print 4 5 4. can you plz elaborate why b is getting incremented twice
Sep 14, 2003 2 #4 xwb Programmer Jul 11, 2002 6,828 GB The order of evaluation is undefined in this instance. Actually, the macro would have been (a++ > b++? a++: b++) a is incremented twice that is probably why you are getting 5. Upvote 0 Downvote
The order of evaluation is undefined in this instance. Actually, the macro would have been (a++ > b++? a++: b++) a is incremented twice that is probably why you are getting 5.
Sep 14, 2003 Thread starter #5 Sac123 Programmer Jul 24, 2003 3 IN Hi xwb, thanks a lot Upvote 0 Downvote
Sep 22, 2003 #6 PerFnurt Programmer Feb 25, 2003 972 SE This is a nice illustration on why macros should be avoided. /Per if (typos) cout << "My fingers are faster than my brain. Sorry for the typos."; Upvote 0 Downvote
This is a nice illustration on why macros should be avoided. /Per if (typos) cout << "My fingers are faster than my brain. Sorry for the typos.";