Kudret is correct. Sangeetha, I am just refering the main line in your code.
Here you assignment and logical check operation occurring simaltaneously. For || and && operator associativity is from left to right. So here first a will be evaluated to true (now the first expression is true), then it will encounter the short circuit || operator and will not check further due to true value of first expression and hence you are getting the output as you mentioned.
You are also right that && has higher precedence than ||.
Just take out one "|" So now we dont have Conditional OR, what we have now is just logical OR. IN this situation, all the stuff in the paranthesis have to be evaluated strictly following the evaluation order, precedence rules, associativity, blah, blah... The result must be true, true, true as expected by you. [ September 01, 2005: Message edited by: Kalyana Sundaram ]
Only those who will risk going too far can possibly find out how far one can go !!!
Joined: May 16, 2005
kalyana you are right, when the short circuit operator is changed to bitwise, i do agree your answer.
But still i did not get the answer for operator precedence between && and ||. Please help me..
What you have forgotten is that an expression is evaluated from left to right after the precedence grouping has been performed.
is certainly grouped according to precedence as:
but the expression is then evaluated from left to right. That is, a is set to true, and the result of that assignment expression is true. The logical or (||) now short circuits because it already has a true argument. So the result of the whole expression is true and the assignments to b and c did not take place.