can you have a situation like
or does it have to beCode:int a = 3;
int b = 3;
int c = 3;
if (a == b == c){
cout<< "yes";
}
Code:if (a == b && a == c){
cout<< "yes";
}
Printable View
can you have a situation like
or does it have to beCode:int a = 3;
int b = 3;
int c = 3;
if (a == b == c){
cout<< "yes";
}
Code:if (a == b && a == c){
cout<< "yes";
}
It can be the former (but you may get a result which you did not expect), but it should be the latter.
The second one will do what you want. The first one does:
Which can be re-written as:Code:a == (b == c)
--Code:temp = (b == c); // Makes a value of 0 or 1. (parenthesis not strictly necessary)
a == temp;
Mats
So, to clarify (for myself),
results in false, even through a==b is true and b==c is true. Correct?Code:a==b==c ;
Todd
Correct, except for special cases, e.g., a = b = c = 1.Quote:
results in false, even through a==b is true and b==c is true. Correct?