Relational Operators
Relational operators are used to determine whether two numbers are equal, or if one is greater or less than the other. Every relational expression returns either 1 (true) or 0 (false). The relational operators are presented in Table 4.1. |
If the integer variable myAge has the value 39, and the integer variable yourAge has the value 40, you can determine whether they are equal by using the relational “equals” operator:
myAge == yourAge; // is the value in myAge the same as in yourAge?
This expression evaluates to 0, or false, because the variables are not equal. The expression
myAge > yourAge; // is myAge greater than yourAge? ...
Get Sams Teach Yourself C++ in 24 Hours, Third Edition 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.