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

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. :)

What I got from it was this:

The sequence points listed in the C standard are:

  • at the end of the evaluation of a full expression (a full expression is an expression statement, or any other expression which is not a subexpression within any larger expression);
  • at the ||, &&, ?:, and comma operators; and
  • at a function call (after the evaluation of all the arguments, and just before the actual call).

Conspicuously missing was the assignment operator.

I still find sequence points confusing, so I do my best simply to avoid writing code that makes great use of knowing exactly where they are.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.