The first expression
b == c || b == dwill give you a value of true if beither cor d.
The second expression
b == (c || d)will check only if it is beither 0 or 1, because the output c || dis binary.
Consider this code:
#include <iostream>
using namespace std;
int main() {
int b=10,c=9,d=10;
cout << (b ==c || b ==d )<<endl;
cout<< ( b == ( c || d)) <<endl;
d=11;
cout << (b ==c || b ==d )<<endl;
cout<< ( b == ( c || d)) <<endl;
return 0;
}
Output signal
1
0
0
0
Now you can clearly see that both expressions are not the same.
user2897690
source
share