ICSE Class 10 Computer Applications Question 9 of 26

Operators in Java — Question 9

Back to all questions
9
Question

Question 9

If a = 5, b = 9, calculate the value of:
    a += a++ - ++b + a

Answer

    a += a++ - ++b + a
⇒ a = a + (a++ - ++b + a)
⇒ a = 5 + (5 - 10 + 6)
⇒ a = 5 + 1
⇒ a = 6

a++ first uses the current value of a (which is 5) in the expression and then increments it to 6. ++b first increment the current value of b to 10 and uses this incremented value in the expression.