+ 2

Can anyone explain more about postfix increment/decrement?

28th Aug 2019, 6:15 AM
Innocent Chobesha
Innocent Chobesha - avatar
5 Respuestas
+ 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
28th Aug 2019, 9:47 AM
D_Stark
D_Stark - avatar
+ 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
28th Aug 2019, 9:57 AM
D_Stark
D_Stark - avatar
+ 2
Thanks for helping
28th Aug 2019, 9:52 AM
Innocent Chobesha
Innocent Chobesha - avatar
+ 2
Am really humbled I have learnt something so far Thanks once again
28th Aug 2019, 10:04 AM
Innocent Chobesha
Innocent Chobesha - avatar