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

Posted by Kenneth on Programmers See other posts from Programmers or by Kenneth
Published on 2011-03-19T16:38:17Z Indexed on 2011/03/20 0:17 UTC
Read the original article Hit count: 587

Filed under:
|

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)

© Programmers or respective owner

Related posts about postfix

Related posts about prefix