-
C (
http://www.daniweb.com/forums/forum118.html)
| himanjim | Jul 30th, 2006 7:26 pm | |
| Need a little guidance?? Can u anybody of u explain me how the following statement works??
y=x++<=5;:!: |
| Dave Sinkula | Jul 30th, 2006 8:12 pm | |
| 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. |
| WolfPack | Jul 30th, 2006 11:54 pm | |
| 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? |
| Dave Sinkula | Jul 31st, 2006 12:12 am | |
| 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. |
| WolfPack | Jul 31st, 2006 12:27 am | |
| Re: Need a little guidance?? So the error was this statement?
y=x++<=5; is equivalent to y=(x++<=5);. |
| Dave Sinkula | Jul 31st, 2006 12:28 am | |
| Re: Need a little guidance?? |
| himanjim | Jul 31st, 2006 6:53 am | |
| 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. |
| WolfPack | Jul 31st, 2006 6:54 am | |
| 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. |
| himanjim | Jul 31st, 2006 7:05 am | |
| Re: Need a little guidance?? My knowledge suggest that asignment is done before the incrementation. |
| Dave Sinkula | Jul 31st, 2006 9:18 pm | |
| 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. |
| All times are GMT -4. The time now is 2:04 am. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC