Ernest Friedman-Hill wrote: here "x" is "p+1", so we get "p+1*p+1",evaluates to p + (1 * p) + 1 = 7
Campbell Ritchie wrote: . . . or better still, #define SQUARE(x) ((x)*(x))
Ernest Friedman-Hill wrote:
Campbell Ritchie wrote: . . . or better still, #define SQUARE(x) ((x)*(x))
That's the classic dodge, although then the follow-on question is "Why does this give 12 rather than 9?"
What about SQUARE(x++)?Ernest Friedman-Hill wrote:
Campbell Ritchie wrote: . . . or better still, #define SQUARE(x) ((x)*(x))
That's the classic dodge, although then the follow-on question is "Why does this give 12 rather than 9?"
Campbell Ritchie wrote:What about SQUARE(x++)?
You jestArjun Srivastava wrote:. . . serious discussion here. . . .
Campbell Ritchie wrote:You jest
find a C implementation which returns 12 from SQUARE(x++).
It's undefined because the standard says so. Put it through a decent compiler like gcc - Wall -std=c99 to get warning: operation on 'i' may be undefined. The fact that it compiles on a particular implementation (the ancient Turbo C by the looks of it) is not relevant. You can do it, just be aware that the results may not always be what you expect.
Campbell Ritchie wrote:I tried your code on "gcc" and got 9 49 7 as output.
No, but I didn't use -WallArjun Srivastava wrote: . . . Hi sir, did you also get any warning while compiling this code on gcc?
Yes. . . It follows the same pattern.
Does this make any sense?
Probably not.can i use this technique for solving pseudo codes output?
Campbell Ritchie wrote:
I challenge you to find a C implementation which returns 12 from SQUARE(x++).
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|