Boolean operators

The == operator tests whether two values are exactly the same. If you test two integers then the test is obvious; for example, if x is 2 and y is 3, then x == y is obviously false. However, two real numbers may not be the same even when you think so:

    double x = 1.000001 * 1000000000000;     double y = 1000001000000;     if (x == y) std::cout << "numbers are the same";

The double type is a floating-point type held in 8 bytes, but this is not enough for the precision being used here; the value stored in the x variable is 1000000999999.9999 (to four decimal places).

The != operator tests if two values are not true. The operators > and <, test two values to see if the left-hand operand is greater than, or less than, the right-hand ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.