Why does the output value of (a) change when you use the | operator instead of the operator || is used? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does the output value of (a) change when you use the | operator instead of the operator || is used?

int a = 2; int b = 3; if ((a < b) || (++ a == b)) { System . out. println ("a = " + a); System . out. println ("b = " + b); } :::RESULT::: a = 2 b = 3 UNDERSTOOD but when: int a = 2; int b = 3; if ((a < b) | (++ a == b)) { System . out. println ("a = " + a); System . out. println ("b = " + b); } :::RESULT::: a = 3 b = 3 WHY? How is it calculated exactly, please?

30th Apr 2020, 5:04 AM
Mohammad Ala Tahhan
Mohammad Ala Tahhan - avatar
2 Answers
0
First of all the result of the first code is a = 2, b = *4*. And second if I understood this then it works as || operator but it doesn't stop if it already found a true part of the if statement.
30th Apr 2020, 5:52 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
0
can you tell me what does that" if((a<b)l(++a==b))"means
4th May 2020, 4:39 PM
Sudip Giri
Sudip Giri - avatar