I thought i am done with operators and expressions in C…But i was wrong.
Expressions ++x && ++y || ++z , is evaluated with my logic. But the logic failed when i tried ++x || ++y && ++z.
I thought i am done with operators and expressions in C…But i was wrong.
Expressions ++x && ++y || ++z , is evaluated with my logic. But the logic failed when i tried ++x || ++y && ++z.
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
I face same problem as u faced if U get the concept plz explain on the post.
++x && ++y || ++z
The above expression is evaluated on the basis of precedence order.
++(variable) > && (logical and) > || (logical or ) precedence order
It means that the expression is evaluated as ((++x && ++y ) || ++z))
let assign x =1, y = 2, z = 3
the expression is evaluated as
x = 2, y = 3, z = 3
Note that is NOT evaluated because
CASE 1
(value1) && (value2)
when value1 = 0, The result become 0 either another value2 = 0 or value2 = 1,
so compiler will NOT evaluate other value2 if left side value1 is 0,
the right side value is evaluated only if left side value1 is equal to 1.
CASE 2
(value1) || (value2)
when value1 = 1, The result become 0 either another value2 = 1 or value2 = 0,
so compiler will NOT evaluate other value2 if left side value1 is 1,
the right side value is evaluated only if left side value1 is equal to 0.
I hope you got understand.
I understood your logic Sir, i too had same…But the result of expression ++x || ++y && ++z; (with x =-1).is not as this logic.