In the term relational operator, relational refers to the relationships that values can have with one
another. In the term logical operator, logical refers to the ways these relationships can be connected.
Because the relational and logical operators often work together, they are discussed together here.
The idea of true and false underlies the concepts of relational and logical operators. In C, true is any
value other than zero. False is zero. Expressions that use relational or logical operators return 0 for
false and 1 for true.
NOTE
Like C89, C99 defines true as nonzero and false as zero. However, C99 also defines
the _Bool data type, which can hold the values 1 and 0. See Part Two for details.
Table 2-5 shows the relational and logical operators. The truth table for the logical operators is
shown here using 1's and 0's.
p q p && q p || q !p
0 0 0 0 1
0 1 0 1 1
1 1 1 1 0
1 0 0 1 0
Both
Thursday, August 28, 2008
Relational and Logical Operators
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment