C: Operators - Relational Operators
(Page 3 of 4 )
When you wish to compare operands, you use relational operators. While I am going to touch on these briefly here, I will go more in depth with them when we cover statements, such as If, While, and For.
Here is a pretty table showing some of the relational operators:
Operator | What it Does | Example |
< | Less than | 1 < 2 |
> | Greater than | 2 > 1 |
<= | Less than or equal to | 1 <=1 |
>= | Greater than or equal to | 3 >= 2 |
“==” (note: the quotations are added here for display purposes only; you do not include them in the operator) | Equal to | 1 == 1 |
!= | Not equal to | 1 != 2 |
Logical Operators
As with relational operators, we will cover logical operators more in depth when we look at statements. For now, satisfy your curiosity with this brilliant table showcasing some of them:
Operator | What it Does | Example |
&& | Logical AND tests 2 conditions to see if they are true | 5 > 4 && 5 < 6 |
|| | Logical OR checks to see if any one of two expressions is true | b <c || b <d |
! | Logical NOT evaluates to true if the expression is false and false if the expression is true | ! 2 > 3 (result would be true, as 2 is not greater than 3) |
Next: Assignment Operators >>
More BrainDump Articles
More By James Payne