C and C++ have the same control statements as Java: if, while, for, switch and do while, with break and continue if you want out early, or just can't seem to stop, respectively. Since these involve making decisions, they require a boolean type. Java has the basic type boolean for this purpose; couldn't be simpler. C++, however, has managed to make it not simple.
Plain C does not have a boolean type. Instead, it uses integer under the following general rules:
C++ inherited this arrangement, but eventually added a boolean type to C++ (and called it bool, just to keep you from spelling right the first time). To maintain compatibility with C, bool converts freely to and from integer under similar rules. Specifically:
The bottom line is to produce the same behavior in either dialect, just using different type rules to get there.
C: Result is 1 or 0.
C++: Result is true or false.
In C: expect integer values, treating zero as false and non-zero as true. Produce 1 or 0.
In C++: expect boolean values. If integer(s) are present, convert to bool and produce true or false by the usual meaning of “and” and “or”.
if(n != 0 && sum / n > 1.0) ...
C and C++ logical operators use short-circuit evaluation, the same as Java.
When you want an if, but need an expression.
max = a < b ? b : a;
cout << "Max is " << a < b ? b : a << endl