Programming in C

(Barry) #1
444 Appendix A C Language Summary

a - b subtracts bfrom a;
a * b multiplies aby b;
a / b divides aby b;
i % j gives the remainder of idivided by j.
In each expression, the usual arithmetic conversions are performed on the operands (see
Section 5.17). If ais unsigned,–ais calculated by first applying integral promotion to it,
subtracting it from the largest value of the promoted type, and adding 1 to the result.
If two integral values are divided, the result is truncated. If either operand is negative,
the direction of the truncation is not defined (that is, –3 / 2 might produce –1 on some
machines and –2 on others); otherwise, truncation is always toward zero (3 / 2 always
produces 1). See Section 5.15 for a summary of arithmetic operations with pointers.

5.4 Logical Operators


Given that
a, b are expressions of any basic data type except void, or are both
pointers;
then the expression
a && b has the value 1 if both aand bare nonzero, and 0 otherwise (and bis
evaluated only if ais nonzero);
a || b has the value 1 if either aor bis nonzero, and 0 otherwise (and bis
evaluated only if ais zero);
! a has the value 1 if ais zero, and 0 otherwise.
The usual arithmetic conversions are applied to aand b(see Section 5.17).The type of
the result in all cases is int.

5.5 Relational Operators


Given that
a, b are expressions of any basic data type except void, or are both
pointers;
then the expression
a < b has the value 1 if ais less than b,and 0 otherwise;
a <= b has the value 1 if ais less than or equal to b,and 0 otherwise;
a > b has the value 1 if ais greater than b,and 0 otherwise;
a >= b has the value 1 if ais greater than or equal to b, and 0 otherwise;
a == b has the value 1 if ais equal to b,and 0 otherwise;
a != b has the value 1 if ais not equal to b,and 0 otherwise.

20 0672326663 AppA 6/10/04 2:01 PM Page 444

Free download pdf