Key Concepts

One aspect of intelligence is the ability to adjust one's responses to the circumstances. Thus, selection statements are the foundation for developing programs that behave intelligently. In C, the if, if else, and switch statements, along with the conditional operator (?:), implement selection.

The if and if else statements use a test condition to determine which statements are executed. Any non-zero value is treated as true, while zero is treated as false. Typically, tests involve relational expressions, which compare two values, and logical expressions, which use logical operators to combine or modify other expressions.

One general principle to keep in mind is that if you want to test for two conditions, you should use a logical ...

Get C Primer Plus, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.