943,989 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1983
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 30th, 2006
0

Need a little guidance??

Expand Post »
Can u anybody of u explain me how the following statement works??
y=x++<=5;:!:
Similar Threads
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
himanjim is offline Offline
67 posts
since Jul 2006
Jul 30th, 2006
0

Re: Need a little guidance??

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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 30th, 2006
0

Re: Need a little guidance??

Quote originally posted 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.
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?
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 31st, 2006
0

Re: Need a little guidance??

Quote originally posted by WolfPack ...
Is x incremented before or after the result of the comparison is assigned to y?
After.
Quote originally posted by WolfPack ...
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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 31st, 2006
0

Re: Need a little guidance??

So the error was this statement?
y=x++<=5; is equivalent to y=(x++<=5);.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 31st, 2006
0

Re: Need a little guidance??

Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 31st, 2006
0

Re: Need a little guidance??

Quote originally posted by WolfPack ...
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.
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
himanjim is offline Offline
67 posts
since Jul 2006
Jul 31st, 2006
0

Re: Need a little guidance??

I know that it is done after the comparison. I wanted to know if it was done after or before the assignment.
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Jul 31st, 2006
0

Re: Need a little guidance??

My knowledge suggest that asignment is done before the incrementation.
Reputation Points: 14
Solved Threads: 1
Junior Poster in Training
himanjim is offline Offline
67 posts
since Jul 2006
Jul 31st, 2006
0

Re: Need a little guidance??

Quote originally posted by WolfPack ...
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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Getting started in MFC, good links?
Next Thread in C Forum Timeline: serial I/O, check for input





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC