+ 2
Can anyone explain more about postfix increment/decrement?
5 Respostas
+ 3
The simplest way to see this in action is the print the increment directly to console.
//declare a variable and assign it a value
int x = 0;
//so here jn the println method we use the original value and print it, straight after it uses the value of x it then increment it by 1 but you dont see this until next time you use x.
System.out.println(x++);//output 0
//⬇️here the value of x is now 1 because as soon as x was used in above method straight after the value increased by 1
System.out.println(x);//output 1
+ 3
Innocent Chobesha no probs.
If you look at were the ++ are that when the increment happens
++x increment before using x
x++ increment after using x
+ 2
Thanks for helping
+ 2
Am really humbled
I have learnt something so far
Thanks once again