From the course: C Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using logical operators

Using logical operators - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Using logical operators

- The C language has two primary logical operators, 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 expression 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. In line A, this expression reads, if the value of variable a is greater than six and the value of variable a is less than 15. If both expressions are true, the if statement evaluates true and the putchar statement outputs an asterisk. In the while loop, the value of variable a loops from one through 20, and this test is performed on each of those values. Build and run, and you see the asterisks are prefixed only on values between six and 15. Now edit the logical expression so that it reads a is less…

Contents