0

What is the difference between x++ and ++x?

22nd Dec 2017, 9:04 PM
Martin Sidorov
Martin Sidorov - avatar
3 Answers
+ 4
They both increase the value of x, but x++ first use the value, and ++x first increase. For example, x=0; y=x++; // y=0, x=1 z=++y; // z=1, y=1
22nd Dec 2017, 9:13 PM
Petr Leliaev
Petr Leliaev - avatar
+ 3
post increment and x++ pretty increment ++x
22nd Dec 2017, 9:34 PM
Android Boi
Android Boi - avatar
+ 3
If you do: int x = 5; And then output x++, it will output 5 then increment x. If you output ++x, it will increment x and then output 6.
22nd Dec 2017, 9:45 PM
Jacob Pembleton
Jacob Pembleton - avatar