+ 1
--x and x--
why do we use --x instead of x-- in this code? Thanks!
3 Respostas
+ 27
--x is a predecrement.
x-- is a postdecrement.
int x = 5;
System.out.println(--x); // outputs 4 System.out.println(x--); // outputs 4
if only x--
output:
5
+ 3
Another difference is that x-- makes a copy of x, so it is slower than --x.
So if it makes no difference which one you use you should use --x.
0
coz I found that there' no output when I change x-- from --x in the given code. so I was doubt