< previous page page_191 next page >

Page 191
cin >> i >> j;
lessThan = (i < j);  // Compare i and j with the less than
                      // relational operator, and assign the
                      //  truth value to lessThan
By comparing two values, we assert that a relationship (like less than) exists between them. If the relationship does exist, the assertion is true; if not, it is false. These are the relationships we can test for in C++:
==
Equal to
!=
Not equal to
>
Greater than
<
Less than
>=
Greater than or equal to
<=
Less than or equal to

In C++, the result of a comparison is the int value 1 (meaning TRUE) or 0 (meaning FALSE). For example, if x is 5 and y is 10, the following expressions all have the value 1 (TRUE):
x != y
y > x
x < y
y >= x
x <= y
If x is the character M and y is R, the expressions are still TRUE because the relational operator <, used with letters, means comes before in the alphabet, or, more properly, comes before in the collating sequence of the character set. For example, in the widely used ASCII character set, all of the uppercase letters are in alphabetical order, as are the lowercase letters, but all of the uppercase letters come before the lowercase letters. So
'M' < 'R'
and
'm' < 'r'
are TRUE, but
'm' < 'R'

 
< previous page page_191 next page >