Need a little guidance??

Reply

Join Date: Jul 2006
Posts: 67
Reputation: himanjim is an unknown quantity at this point 
Solved Threads: 1
himanjim himanjim is offline Offline
Junior Poster in Training

Need a little guidance??

 
0
  #1
Jul 30th, 2006
Can u anybody of u explain me how the following statement works??
y=x++<=5;:!:
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,309
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 228
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need a little guidance??

 
0
  #2
Jul 30th, 2006
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need a little guidance??

 
0
  #3
Jul 30th, 2006
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?
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,309
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 228
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need a little guidance??

 
0
  #4
Jul 31st, 2006
Originally Posted by WolfPack
Is x incremented before or after the result of the comparison is assigned to y?
After.
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need a little guidance??

 
0
  #5
Jul 31st, 2006
So the error was this statement?
y=x++<=5; is equivalent to y=(x++<=5);.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,309
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 228
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need a little guidance??

 
0
  #6
Jul 31st, 2006
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 67
Reputation: himanjim is an unknown quantity at this point 
Solved Threads: 1
himanjim himanjim is offline Offline
Junior Poster in Training

Re: Need a little guidance??

 
0
  #7
Jul 31st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need a little guidance??

 
0
  #8
Jul 31st, 2006
I know that it is done after the comparison. I wanted to know if it was done after or before the assignment.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 67
Reputation: himanjim is an unknown quantity at this point 
Solved Threads: 1
himanjim himanjim is offline Offline
Junior Poster in Training

Re: Need a little guidance??

 
0
  #9
Jul 31st, 2006
My knowledge suggest that asignment is done before the incrementation.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,309
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 228
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need a little guidance??

 
0
  #10
Jul 31st, 2006
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC