Are there real world applications where the use of prefix versus postfix operators matters

postfixprefix

In college it is taught how you can do math problems which use the ++ or — operators on some variable referenced in the equation such that the result of the equation would yield different results if you switched the operator from postfix to prefix or vice versa. Are there any real world applications of using postfix or prefix operator where it makes a difference as to which you use? It doesn't seem to me (maybe I just don't have enough experience yet in programming) that there really is much use to having the different operators if it only applies in math equations.

EDIT: Suggestions so far include:

  1. function calls //f(++x) != f(x++)
  2. loop comparison //while (++i < MAX) != while (i++ < MAX)
  3. operations on objects where ++ and — have been overloaded

Best Answer

prefix and postfix are not necessary, they are just shortcuts.

y = x++;

means

y = x;
x = x + 1;

however y = ++x; means

x = x + 1;
y = x;

Likewise, calling the function f as f(x++) is not the same as saying f(++x)