Boolean expressions

Boolean expressions can be of the same general kinds as arithmetic ones.

No simple constants are defined, for True and False, however. C treats zero integer values as equivalent to false and non-zero integers to true.

The common Boolean operators are shown in the tables. They all produce the value zero for false and one for true.

We can store Boolean values in integer variables, but we might wish to use a typedef to alias these to Boolean for clarity.

Comparisons

The commonest way of obtaining a Boolean value is by making a comparison. These all work on any two expressions of matching type and make the comparison indicated.
==equality
!=inequality
<less than
<=less than or equal
>greater than
>=greater than or equal

Exercises on this section.


Next.

Back to Contents page.