Increment Decrementsuggest change
The increment and decrement operators exist in prefix and postfix form.
int a = 1; int b = 1; int tmp = 0; tmp = ++a; /* increments a by one, and returns new value; a == 2, tmp == 2 */ tmp = a++; /* increments a by one, but returns old value; a == 3, tmp == 2 */ tmp = --b; /* decrements b by one, and returns new value; b == 0, tmp == 0 */ tmp = b--; /* decrements b by one, but returns old value; b == -1, tmp == 0 */
Note that arithmetic operations do not introduce sequence points, so certain expressions with
-- operators may introduce undefined behaviour.
Found a mistake? Have a question or improvement idea? Let me know.
Table Of Contents