Node:Special Assignment Operators ++ --, Next:, Previous:Unary Operator Precedence, Up:Expressions and operators



Special Assignment Operators ++ and --

C has some special operators that can simplify code. The simplest of these are the increment and decrement operators:


++
increment: add one to
--
decrement: subtract one from

You can use these with any integer or floating point variable (or a character in some cases, carefully). They simply add or subtract 1 from a variable. The following three statements are equivalent:

variable = variable + 1;
variable++;
++variable;

So are these three:

variable = variable - 1;
variable--;
--variable;

Notice that the ++ and -- operators can be placed before or after the variable. In the cases above, the two forms work identically, but there is actually a subtle difference. (See Postfix and prefix ++ and -, for more information.)