HP C A.06.05 Reference Manual
Expressions and Operators
Relational Operators (>, >=, <, ==, !=)
Chapter 5128
Evaluation of Relational Expressions
Relational expressions are often called Boolean expressions, in recognition of the
nineteenth-century mathematician and logician, George Boole. Many programming
languages, such as Pascal, have Boolean data types for representing true and false. The C
language, however, represents these values with integers. Zero is equivalent to false, and any
nonzero value is considered true.
The value of a relational expression is an integer, either 1 (indicating the expression is true)
or 0 (indicating the expression is false). The examples in the following table illustrate how
relational expressions are evaluated:
Because Boolean values are represented as integers, you can write
if (j)
statement
;
If j is any nonzero value,
statement
is executed; if j equals 0,
statement
is skipped.
Likewise, the statement
if (isalpha(ch))
is exactly the same as
if (isalpha(ch) != 0)
The practice of using a function call as a Boolean expression is a common idiom in C. It is
especially effective for functions that return 0 if an error occurs, since you can use a construct
such as
Table 5-13 Relational Expressions
Expression Value
-1 < 0 1
0 > 1 0
5 == 5 1
7 != -3 1
1 >= -1 1
1 > 10 0