Dan chisholm Mock exam
class EBH202 {
static boolean a, b, c;
public static void main (
String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
Ans) Prints: true,false,false
Explanation given first a= true is evaluated and since this is true the other part is not evaluated my question is when is left to right and operator precedence evaluated.
I was under the impression that since && has higher precedence over || the expressions
(b = true) && (c = true) is evaluated first followed by (a = true), can someone explain to me when the operands and precedence are evaluated
Also
int i=0, j = ++i + ((++i * ++i) % ++i) + ++i; The output of j = 8 eval as 1 + ( (2 *3) % 4) + 5
Can someone give me an example which justifies the statement that the prefix unary operator associates from Right to Left?