C: Logical Operators
(Page 1 of 4 )
In our last two articles we talked about statements and working with text in C. In this article we are going to learn to use a logical operator alongside our statements, and work with the various loops (hopefully). We'll start with a short review of what we already know about logical operators, and then we'll dive right in.
Working with Logical Operators
We touched on logical operators briefly in a prior article. As a reminder, here is a table showcasing logical operators and their purposes:
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) |
As you can see, there are three logical operators: the AND (&&), the OR (||) and the NOT(!).
Next: Logical AND >>
More BrainDump Articles
More By James Payne