+ 1

Can anyone explain me this code?

int a = 5; int b = 3; System.out.print(a++ + b++); System.out.print(a + 1 + b); System.out.print(--a + --b); output: 8118

17th Mar 2019, 12:24 PM
Purvesh Pawar
Purvesh Pawar - avatar
3 Answers
+ 1
I'll try to explain it - first print statement : postincrement => it is 5 + 3 => 8 ( the values are not saved in "a" and "b"). Second print : the values now are saved in the variables so => 6 + 1 + 4 => 11. The last print here is preincrement operator on both variables => first we change the values in the variables => decrease "a" and "b" by one => 5 + 3 => 8.
17th Mar 2019, 12:37 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
TheWhiteCat thanks
17th Mar 2019, 12:40 PM
Purvesh Pawar
Purvesh Pawar - avatar
+ 1
Purvesh Pawar , you are welcome 😉
17th Mar 2019, 2:03 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar