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"; }
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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.results in false, even through a==b is true and b==c is true. Correct?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)