Side Effects


  • Expressions that change the value of one or more variables are said to have a side effect.

  • For example, an expression that uses the assignment operator has a side effect.

  • Since side effects can be unpredictable, expressions with side effects should be avoided.

  • The only exception is simple assignment statements.

    A program with unpredictable side-effects:

    Sample runs on different machines give different results! This is because C does not explicitly say if the left subexpression or the right subexpress of a binary operator should be evaluated first.