From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using logical operators

Using logical operators

- [Instructor] The C languages' two primary logical operators are AND and OR. The logical and operator is two ampersands. For a logical AND expression to be true, both of its conditions must be true. The logical OR operator is two pipes or vertical bars. For a logical OR operation to be true, either of its conditions must be true. Typically, the logical expressions are used with relational operators as shown in this exercise file. At line nine, if the value of variable A is greater than 6 and its value is less than 15, this expression evaluates true, because both conditions are true. As the value of variable A loops from 1 to 20, each value is processed in this manner. In the output, you see asterisks prefixing the output from lines 7 through 14. Now edit the logical expression so that it reads: When ( a < 6 || a > 15 ) Can you guess what the output might be? Only values less than 6 and greater than 15 have asterisks. Edit the expression again. Let's replace it with ( a >= 16 || a ==…

Contents