Sams Teach Yourself C in 21 Days

(singke) #1
The Pieces of a C Program: Statements, Expressions, and Operators 87

4



  • Both expressions are evaluated, with the left expression being evaluated first.

  • The entire expression evaluates to the value of the right expression.
    For example, the following statement assigns the value of btox, then increments a, and
    then increments b:
    x = (a++ , b++);
    Because the ++operator is used in postfix mode, the value of b—before it is incre-
    mented—is assigned to x. Using parentheses is necessary because the comma operator
    has low precedence, even lower than the assignment operator.
    As you’ll learn in tomorrow’s lesson, the most common use of the comma operator is in
    forstatements.


DOuse the logical operators &&and||
instead of nesting ifstatements.

DON’Tconfuse the assignment operator
(=) with the equal to (==) operator.

DO DON’T


Operator Precedence Revisited ............................................................................


Table 4.11 lists the C operators in order of decreasing precedence. Operators on the same
line have the same precedence.

TABLE4.11 C Operator Precedence
Level Operators
1 () [] ->.
2! ~ ++ -- *(indirection)&(address of)(type)
sizeof + (unary)-(unary)
3 *(multiplication)/ %
4 + -
5 << >>
6 < <= > >=
7 == !=
8 &(bitwiseAND)
9 ^
10 |

07 448201x-CH04 8/13/02 11:15 AM Page 87

Free download pdf