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 - C Tutorial
From the course: C Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Working with math operators3m 3s
-
(Locked)
Challenge: Do some math49s
-
(Locked)
Solution: Do some math1m 29s
-
(Locked)
Using assignment operators1m 44s
-
(Locked)
Obeying the order of precedence3m 13s
-
(Locked)
Challenge: Get the order correct54s
-
(Locked)
Solution: Get the order correct1m 11s
-
(Locked)
Working with relational operators3m 39s
-
(Locked)
Using logical operators3m 49s
-
(Locked)
Understanding bitwise operators3m 36s
-
(Locked)
Shifting bits3m 18s
-
(Locked)
Exploring unary operators3m 44s
-
(Locked)
Challenge: Binary math1m 5s
-
(Locked)
Solution: Binary math2m 11s
-
-
-
-