189k views
5 votes
Is the expression a || b the same as a && !b

User Ikesha
by
8.0k points

2 Answers

2 votes
You could test it
case (1)
a =true, b=false
true || false = true
true && !false = true
PASSED!

a=false b= true
false || true = true
false && !true = false
FAILED!

also try a=true, b =true

so the it is not the same
User Jovanka
by
8.6k points
4 votes
Most definitely not! A || B is A OR B, if A is true OR B is true, the statement will be true. A && !B is A AND !B, only if A is true AND B is false will the statement be true. With OR, B can be true and the statement will pass.
User Joe Bowbeer
by
7.3k points