Increment, Decrement, Shorthand Operators and Precedence in Java (ICSE Class 10)
Updated 17 October 2026 · Fact-checked
Prefix (++x) increases x first and then uses the new value; postfix (x++) uses the old value first and then increases x. Shorthand operators such as x += 3 mean x = x + 3. When an expression has several operators, those with higher precedence work first; operators of the same level follow their associativity (mostly left to right; assignment and unary operators go right to left).
Both end with x = 6, but prefix increases before copying to y, while postfix copies the old value first, so y differs.
Illustration drawn for QuestionBuddy.
Understand Increment, Decrement, Shorthand Operators and Precedence
Increment and decrement. ++ adds 1 and -- subtracts 1 from a variable.
- Prefix
++x: increase first, then use the value. If x is 5,y = ++x;makes x = 6 and y = 6. - Postfix
x++: use the value first, then increase. If x is 5,y = x++;makes y = 5 and x = 6.
Used alone as a statement (x++;), both forms just add 1.
Shorthand (compound) assignment. x += 3 is x = x + 3. Similarly -=, *=, /=, %=. The right side is evaluated completely first: x *= 3 + 2 means x = x * (3 + 2).
Types of operators (as in the syllabus): arithmetic (+ - * / %), relational (< > <= >= == !=), logical (&& || !), assignment, increment, decrement and shorthand. By the number of operands they are unary (one), binary (two) or ternary (three: condition ? value1 : value2). Bitwise and shift operators are not in the syllabus.
Precedence (highest to lowest).
1. postfix x++ x--
2. prefix ++x --x, unary + - !
3. * / %
4. + -
5. < > <= >=
6. == !=
7. &&
8. ||
9. ternary ?:
10. assignment = += -= *= /= %=
Associativity. Operators of the same precedence are done left to right (e.g. * / %, + -); assignment and the unary operators are done right to left. So 10 - 4 - 2 is (10 - 4) - 2 = 4 and 12 / 4 * 3 is 9, not 1.
Ternary operator. big = a > b ? a : b; gives a if a > b, otherwise b. Ternary operators can be nested.
Counter and accumulator. A counter counts how many times something happens and is increased by a fixed amount (c++). An accumulator collects a running total and is increased by varying amounts (sum += x).
Neighbouring topics: how new and the dot operator work is in the same chapter's other pages and in the "Objects" topics.
Increment, Decrement, Shorthand Operators and Precedence: key facts
- Prefix and postfix
- ++x: change, then use
- x++: use, then change
- Used alone, both add 1
- The same for --.
- Shorthand assignment
- x += y means x = x + y
- x -= y means x = x - y
- x /= y means x = x / y
- x %= y means x = x % y
- the whole right side is solved first
- The whole right side is calculated first.
- Precedence order
- postfix
- prefix and unary
- multiply, divide, remainder
- add, subtract
- < > <= >=
- == !=
- &&
- ||
- ?:
- assignment
- Brackets override everything.
- Associativity
Binary operators of one level left to right Assignment right to left Unary right to left - 12 / 4 * 3 = 9.
How to answer Increment, Decrement, Shorthand Operators and Precedence questions
Use this routine for expression and output questions.
- 1Write the starting value of every variable.
- 2Rewrite the expression with brackets showing the precedence order.
- 3Move left to right through each level; for x++ take the old value and then update x, for ++x update x and then take the value.
- 4After each statement write the new value of every variable that changed.
- 5For a printing statement, evaluate each part in order; an int joined to a string with + becomes text.
Increment, Decrement, Shorthand Operators and Precedence in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Counter and accumulator
Suppose a quiz program checks 5 answers; for every correct answer it adds the marks of that question to a total and also counts how many answers were correct.
If questions 1, 3 and 4 are correct, with marks 1, 1 and 2, what are the counter and the accumulator at the end?
Try it first, then show the solutionSolution
- The counter is increased by 1 for each correct answer: 3 correct answers.
- The accumulator adds the marks: 1 + 1 + 2 = 4.
Answer: Counter = 3 and accumulator = 4.
Memory hook: Counters count by one; accumulators add what comes.
Tricks to remember Increment, Decrement, Shorthand Operators and Precedence
Short memory aids. Say each one aloud once, then use it on a question the same day.
Prefix = Preview first
++x changes before you see it; x++ shows the old value and then changes.
Use it when: Pre vs post questions.
PEMDAS-like ladder
Unary, then * / %, then + -, then comparisons, then &&, then ||, then ?:, then =.
Use it when: Long expressions.
Equals goes last
The assignment sign is the lowest, so the whole right side is solved before storing.
Use it when: Shorthand operators such as x *= 3 + 2.
Increment, Decrement, Shorthand Operators and Precedence: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Prefix and postfix together · 2 marks · Short answerBoard level
Write the values of x and y:
int x = 5;
int y = x++ + ++x;
System.out.println(x + " " + y);Try it first, then show the solutionSolution
- x++ gives 5 and then x becomes 6; ++x makes x 7 and gives 7. (1 mark)
- y = 5 + 7 = 12 and x is 7, so the line prints x first. (1 mark)
Answer: 7 12
Example 2: Shorthand with increment · 3 marks · Short answerHarder board level
Write the values printed:
int a = 4, b = 3;
a += b++ * 2;
b -= --a;
System.out.println(a + " " + b);Try it first, then show the solutionSolution
- b++ * 2: the old b (3) is used, so 3 * 2 = 6 and b becomes 4. Then a = 4 + 6 = 10. (1 mark)
- --a makes a 9 and gives 9. (1 mark)
- b = 4 - 9 = -5. So a = 9 and b = -5. (1 mark)
Answer: 9 -5
Example 3: Precedence and logical operators · 3 marks · Short answerHarder board level
Find r and q:
int r = 10 + 4 * 3 % 5 - 2;
int p = 5;
boolean q = p > 3 && p < 10 || p == 0;
System.out.println(r + " " + q);Try it first, then show the solutionSolution
- 4 * 3 % 5: same level, left to right: 4 * 3 = 12, then 12 % 5 = 2. (1 mark)
- r = 10 + 2 - 2 = 10. (1 mark)
- p > 3 is true, p < 10 is true, && gives true; || with p == 0 (false) gives true. (1 mark)
Answer: 10 true
Example 4: Case study: counting and totalling · 4 marks · Case-basedHOTS / competency
A teacher's program processes the numbers 1 to 5:
int c = 0, t = 0;
for (int i = 1; i <= 5; i++) {
if (i % 2 == 0)
c++;
else
t += i;
}
System.out.println(c + " " + t);(i) Name the counter and the accumulator. (1)
(ii) Trace the loop and state the output. (2)
(iii) What does the program count and total? (1)
Try it first, then show the solutionSolution
- (i) c is the counter (increased by 1); t is the accumulator (increased by different amounts).
- (ii) i = 1: odd, t = 1. i = 2: even, c = 1. i = 3: t = 4. i = 4: c = 2. i = 5: t = 9. Output: 2 9.
- (iii) It counts the even numbers (2 and 4) and adds up the odd numbers (1 + 3 + 5).
Answer: (i) c counter, t accumulator (ii) 2 9 (iii) counts the evens, sums the odds
Example 5: Ternary operator · 3 marks · Short answerHarder board level
Find the output:
int m = 72, a = 8, b = 12;
String g = m >= 90 ? "A" : m >= 75 ? "B" : m >= 60 ? "C" : "D";
int big = a > b ? a : b;
System.out.println(g + " " + big);Try it first, then show the solutionSolution
- m >= 90 is false, so the next part is evaluated: m >= 75 is false; m >= 60 is true, so g = "C". (1 mark)
- a > b means 8 > 12, which is false, so big takes b = 12. (1 mark)
- Output joins "C", a space and 12. (1 mark)
Answer: C 12
Where students lose marks in Increment, Decrement, Shorthand Operators and Precedence
The slips examiners see most often, and what to write instead.
Mistake: Using the new value for a postfix
In y = x++, y receives the old value; x is increased afterwards.
Wrong working
x = 5; y = x++; y = 6
Right working
x = 5; y = x++; y = 5, x = 6
Do this: Write "use, then change" next to x++.
Usually costs: 1 mark
Mistake: Doing + before * in an expression
* / % have higher precedence than + -.
Wrong working
10 + 4 * 3 = 42
Right working
10 + 4 * 3 = 22
Do this: Draw brackets round * / % first.
Usually costs: 1 mark
Mistake: Misreading shorthand with a bracket-less right side
x *= 3 + 2 means x = x * (3 + 2), not (x * 3) + 2.
Wrong working
x = 5; x *= 3 + 2; x = 17
Right working
x = 5; x *= 3 + 2; x = 25
Do this: Replace the shorthand by the full form with brackets.
Usually costs: 1 mark
Exam tips
- In dry-run questions write a column for every variable and update it after each operator.
- x++ + ++x style lines are asked often; evaluate strictly from left to right.
- Remember division and remainder have the same precedence as multiplication.
- Counters change by a fixed step; accumulators change by varying amounts: use these words.
Practice questions on Increment, Decrement, Shorthand Operators and Precedence
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
What is the value of the expression 10 + 3 * 2?
(a) 26 (b) 16 (c) 19 (d) 12Hint
- comes before +.
Answer
(b) 16
Q2 · 1 mark · Very short answerBoard level
What is the value of x after:
int x = 5; x *= 3 + 2;Hint
Solve the right side first.
Answer
25, since x = x * (3 + 2) = 5 * 5.
Q3 · 2 marks · Short answerHarder board level
Find the output:
int a = 3; int b = a++ * 2 + a; System.out.println(a + " " + b);Hint
a changes after its old value is used.
Answer
4 10 (a++ gives 3 and a becomes 4; b = 3 * 2 + 4 = 10)
Q4 · 2 marks · Short answerHarder board level
Write the output:
int k = 7; System.out.println(k++ + " " + k + " " + --k);Hint
Evaluate the three parts from left to right.
Answer
7 8 7 (k++ gives 7 then k is 8; k gives 8; --k makes k 7 and gives 7)
Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): For the statements x++; and ++x; written alone, the final value of x is the same.
Reason (R): The difference between prefix and postfix is seen only when the value of the expression is used.
(a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.Hint
Is the value of the expression used when written alone?
Answer
(a) Both are true and R explains A.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What does y = x++ do?Show answer
Stores the old value of x in y, then increases x by 1.
2.What does x += 5 mean?Show answer
x = x + 5
3.Name the only ternary operator.Show answer
?:
4.Which has higher precedence: % or +?Show answer
%
5.Give the associativity of the assignment operator.Show answer
Right to left.
6.Are bitwise operators in the Class X syllabus?Show answer
No.
Increment, Decrement, Shorthand Operators and Precedence: frequently asked questions
What is the difference between ++x and x++?
Prefix increases first and uses the new value; postfix uses the old value and then increases.
What is the difference between a counter and an accumulator?
A counter counts occurrences by a fixed step like 1; an accumulator adds varying values to build a total.
What is the value of 12 / 4 * 3?
9. / and * have the same precedence and go left to right: (12 / 4) * 3.