ICSE Class 10 Computer Applications Question 46 of 76

Revising Basic Java Concepts — Question 50

Back to all questions
50
Question

Question 30(b)

What is the value of y after evaluating the expression given below ?

y += ++y + y-- + --y ; when int y = 8

Answer

The value of y will be 33.

Explanation

    y += ++y + y-- + --y
⇒ y = y + ++y + y-- + --y         y = 8
⇒ y = 8 + 9 + y-- + --y              y = 9
⇒ y = 8 + 9 + 9 + --y                 y = 8
⇒ y = 8 + 9 + 9 + 7                    y = 7
⇒ y = 33