0

This is my code snippet.

class Example{
public static void main(String[] args) {
int a=10;
int x;
 x= ++a + ++a;
System.out.println(x);
}
}

Output is 23. Need little help.

sha sha
  • 115
  • 9

1 Answers1

2

You can divide x= ++a + ++a; into 3 pieces.

Firstly, the first ++a will be done. Then the second ++a will be done. Then the + will be done.

So after the first ++a, a will be 11. After the second ++a, a will be 12. After the +, a will be 11 + 12 = 23.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Anton Kolosok
  • 482
  • 9
  • 24