KnowledgeBoat Logo
|

Computer Applications

Assume x = 1 with the following code snippet:

int y = --x;

Which one of the following is true?

  1. x = 1, y = 1
  2. x = 0; y = 0
  3. x = 1; y = 0
  4. x = 0; y = 1

Java Operators

23 Likes

Answer

x = 0; y = 0

Reason — Prefix decrement operator first decrements and then uses the value. Thus, the value of x will be decremented first (making x = 0) and then the value will be assigned to y (making y = 0).

Answered By

14 Likes


Related Questions