A side effect is a change to program state caused while evaluating an expression or executing an operation. In C, modifying an object, storing a value, performing I/O, or changing relevant hidden state can affect later evaluation. section 4.3 section 21.0
Keep side effects separate from value computation:
- Assignment operators, ++, and -- return a value while also modifying an object. section 4.3
- Prefix increment modifies first and returns the new value; postfix increment returns the old value and modifies afterward. section 4.3
- Most operators and function calls do not sequence their operands or argument expressions, so side effects can make the result depend on evaluation order. section 4.6
- Avoid modifying more than one object in a statement and avoid side-effecting function calls inside expressions. section 4.3 section 4.6
Sequencing changes what an expression observes
In `printf("%g and %g\n", f(a), f(b));`, the two function arguments have no guaranteed evaluation order. If either call changes state relevant to the other, the result depends on which call runs first. Separate the calls into statements when their effects matter. section 4.6
an_object @= some_expression;
The compound-assignment form `an_object @= some_expression;` makes an object modification explicit and keeps the side effect at statement level. section 4.3























