KnowledgeBoat Logo

Computer Applications

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

Java Operators

ICSE 2008

226 Likes

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.

Answered By

131 Likes


Related Questions