Section 9.6 Combining Multiple Logic Statements
Sometimes you may want to check whether several statements are true at the same time, or whether at least one of several statements is true, or whether something is not true, etc. We’ll take a look at how do do this in C now.The way to write the logical AND
in C is with two ampersand signs: &&
admin.....open in new window
The way to write the logical OR
in C is with two vertical bars: ||
admin.....open in new window
The way to negate a condition in C is to put an exclamation mark in front of it: !(...)
admin.....open in new window
Investigate 9.4.
Zero is the value which C interprets as false. How could you use a logical operator so that C would interpret anything except zero as false, such as in an if
statement?