Skip to main content
Improved explanation
Source Link
Yash Soni
  • 466
  • 3
  • 11

When you write a++ OR b--, it passes the value 'a' and 'b' currently holds, and then modifies the variables.

So your expression is simply,

boolean d = (0 > 0 && 0 < 0) || -1 < 0; 

Hence dNow while evaluating, (0 > 0 && 0 < 0) -> first expression returns false and you have used short-circuit AND operator. Meaning don't evaluate the right hand side if it isn't necessary. As LHS of && returns false, b-- won't be evaluated.

And we have 'd' is true. Remember,

Post-increment within expressions --> assign current value first, modify later.

Pre-increment within expressions --> modify first, assign updated value later.

Refer this link for better understanding short circuit operators: Short-Circuit Explanation

When you write a++ OR b--, it passes the value 'a' and 'b' currently holds, and then modifies the variables.

So your expression is simply,

boolean d = (0 > 0 && 0 < 0) || -1 < 0; 

Hence d is true. Remember,

Post-increment within expressions -- assign current value first, modify later.

Pre-increment within expressions --> modify first, assign updated value later.

When you write a++ OR b--, it passes the value 'a' and 'b' currently holds, and then modifies the variables.

So your expression is simply,

boolean d = (0 > 0 && 0 < 0) || -1 < 0; 

Now while evaluating, (0 > 0 && 0 < 0) -> first expression returns false and you have used short-circuit AND operator. Meaning don't evaluate the right hand side if it isn't necessary. As LHS of && returns false, b-- won't be evaluated.

And we have 'd' is true. Remember,

Post-increment within expressions --> assign current value first, modify later.

Pre-increment within expressions --> modify first, assign updated value later.

Refer this link for better understanding short circuit operators: Short-Circuit Explanation

Source Link
Yash Soni
  • 466
  • 3
  • 11

When you write a++ OR b--, it passes the value 'a' and 'b' currently holds, and then modifies the variables.

So your expression is simply,

boolean d = (0 > 0 && 0 < 0) || -1 < 0; 

Hence d is true. Remember,

Post-increment within expressions -- assign current value first, modify later.

Pre-increment within expressions --> modify first, assign updated value later.