1.6

Compound Assignment Operators

Compound assignment operators like +=, -=, *=, /=, %= and post-increment/decrement provide shorthand for updating variable values.

1525% of exam
Understand It
Ace It
Context

What this topic is and why it exists

Imagine you're keeping a running tally on a whiteboard.
Every time someone scores a point, you don't erase the whole number and rewrite it from scratch — you just add to what's already there.
That's exactly what compound assignment operators do in Java.
Instead of writing `score = score + 10`, you can write `score += 10`.
It's the same operation, just shorter and cleaner.
The computer looks at whatever value `score` already holds, adds 10 to it, and stores the result right back in `score`.
This shorthand works for all the basic math operations: `-=` subtracts, `*=` multiplies, `/=` divides, and `%=` gives you the remainder.
So `x *= 3` triples whatever `x` currently holds.
Think of the operator as a tiny instruction: "take what's there, do this math, and put the answer back."
There's an even lazier shortcut for the most common case — adding or subtracting just one.
Writing `x++` bumps `x` up by one, and `x--` drops it by one.
You'll see these everywhere, especially in loops.
For the AP exam, just remember: always use them *by themselves* on a line, never buried inside another expression.
Keep it simple, and these little operators will save you a surprising amount of typing and reading time.
1 / 9