Can u anybody of u explain me how the following statement works??
y=x++<=5;:!:

3
Contributors
13
Replies
14
Views
12 Years
Discussion Span
Last Post by Dave Sinkula

If x is less than or equal to 5, y is set to 1 -- otherwise y is set to 0; x is then incremented.

But better would be for you to ask, "I think that this statement does [...]. Is this correct?" Or at least provide a (minimal, but complete and compileable) snippet that shows the full context.

If x is less than or equal to 5, y is set to 1 -- otherwise y is set to 0; x is then incremented.

Is x incremented before or after the result of the comparison is assigned to y? Correct me if I am wrong in the explaination below. `y=x++<=5;` is equivalent to `y=(x++<=5);` .
The part inside the brackets should be evaluated first. So doesn't that mean the binary comparison and the ++ should also be evaluated before the assignment?

Is x incremented before or after the result of the comparison is assigned to y?

After.

Correct me if I am wrong in the explaination below. `y=x++<=5;` is equivalent to `y=(x++<=5);` .
The part inside the brackets should be evaluated first. So doesn't that mean the binary comparison and the ++ should also be evaluated before the assignment?

No.

So the error was this statement? `y=x++<=5;` is equivalent to `y=(x++<=5);` .

So the error was this statement? `y=x++<=5;` is equivalent to `y=(x++<=5);` .

This is the case of post incrementation so increment is done after the comparision.

I know that it is done after the comparison. I wanted to know if it was done after or before the assignment.

My knowledge suggest that asignment is done before the incrementation.

I know that it is done after the comparison. I wanted to know if it was done after or before the assignment.

I'll go out on a limb a little (and search more later) and say that it is done after the comparison and before the assignment.

Grr.

Now just to be an ass I'll change my mind and reverse that last statement of mine.

No, not just to be an ass:
http://c-faq.com/expr/seqpoints.html

My question is why? Why is it a curiousity? Why not just write it without ambiguity?

Now just to be an ass I'll change my mind and reverse that last statement of mine.

No, not just to be an ass:
http://c-faq.com/expr/seqpoints.html

Snarl.

My question is why? Why is it a curiousity? Why not just write it without ambiguity?

When I write code I try to be clear and without ambiguity. But I can't give a answer like that when a newbie asks something about operator call sequence. So I have to be careful on subtle points like that (especially since I am a mod). I will go through the link and see what I can make out from it. :)

I will go through the link and see what I can make out from it. :)