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"; }
This is a discussion on quick question regarding the '==' sign. within the C++ Programming forums, part of the General Programming Boards category; can you have a situation like Code: int a = 3; int b = 3; int c = 3; if ...
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way