Quiz Entry - updated: 2026.07.10
What are compound assignment operators and how do increment/decrement work?
a ●= b is shorthand for a = a ● b; ++/-- add or subtract 1, and prefix updates before the value is used while postfix updates after.
Compound assignment:
c = c + b; → c += b;
c = c >> 2; → c >>= 2;
c = c & a; → c &= a;
Increment/decrement:
// or ++c
c = c + 1; → c++;
// or --c
c = c - 1; → c--;
Prefix vs postfix - the critical difference:
int b = 5;
// a = 5, b = 6 (use THEN increment)
int a = b++;
// a = 6, b = 6 (increment THEN use)
int a = ++b;
Example in expressions:
int x = 5;
// Prints 5, then x becomes 6
printf("%d\n", x++);
// x becomes 7, then prints 7
printf("%d\n", ++x);
Warning: Avoid multiple ++/-- on same variable in one expression:
// UNDEFINED BEHAVIOR! Don't do this.
int a = i++ + ++i;
Go deeper:
Increment and decrement operators — Wikipedia — prefix vs postfix ++/-- semantics.