x = y assignment will almost always evaluate to true (unless y is 0, I think).
For case2, x is 1, which evaluates to true, and since "true OR something" will always be true, it doesn't bother evaluating the right-hand expression.
Same goes for && (AND) logic when the left-hand side is false -- it won't bother evaluating the right-hand side.
No, it's because || has higher precedence than =. Note that this is = (the assignment operator), not == (equality test).
It's clearer if you add the parenthesis around the precedence. Your examples are the same as: if (x = (y || z)) // assign result of y||z to x, then use x in if clause.
Thank you for the anwsers, guys.
Yeah you're right @dhayden. Adding the parenthesis made it so much clearer. But could you please explain why we can't assign z to "x||y"?
Sorry if i asked a silly question. I didn't fully understand Boolean Operations I confused || operator with plain English "or". I thought the result of "x||y" would be either x or y.
Nivekrulol, although you can't assign a value to a *or* b, you can assign a value to multiple variables in a single statement: a=b=3 assigns 3 to a and b. This works because = groups right to left (so it's a=(b=3)) and b=3 is not just a statement, it's an expression whose value is 3.