August 12th, 2013, 01:21 PM
In the above program we get the output as
-2 -2 0 1
how is this expression solved and we get this answer?
August 12th, 2013, 02:25 PM
August 12th, 2013, 02:37 PM
My output is -2201. The result is because of C's short-circuit evaluation. Once it evaluates that ++i is non-zero, the rest of the expression doesn't need to be evaluated because the || will be true regardless of what the value of the other expressions are.
Of course, this behavior may be compiler specific. Also note that when I compile it on gcc with full warnings, it warns me with this message:
warning: suggest parentheses around ‘&&’ within ‘||’
Best not to write code like this if you have trouble trying to figure it out yourself.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo