This chapter describes forming expressions in
C, discusses operator precedence, and provides details about operators
used in expressions.
An expression in C is a collection of operators and operands
that indicates how a computation should be performed. Expressions
are represented in infix notation. Each operator has a precedence
with respect to other operators. Expressions are building blocks
in C. You use the C character set to form tokens. Tokens, combined
together, form expressions. Expressions can be used in statements.
The C language does not define the evaluation order of subexpressions
within a larger expression except in the special cases of the &&,
||,
?:, and ,
operators. When programming in other computer languages, this may
not be a concern. C's rich operator set, however, introduces operations
that produce "side effects." The ++
operator is a prime example. The ++
operator increments a value by 1 and provides the value for further
calculations. For this reason, expressions such as
are dangerous. The language does not specify whether the variable
a is first incremented
and multiplied by 4 or is first incremented and multiplied by 2.
The value of this expression is undefined.