+ 1

Guys i can't understand the difference between prefix and postfix

29th Oct 2017, 4:50 PM
Shehab Ashraf
Shehab Ashraf - avatar
4 Answers
+ 8
It is pretty simple. Pre means before Post means after In your example x = 14; system.out.print (x++); 14 is printed because x is incremented 'after' (postfix) the print statement is executed.
29th Oct 2017, 11:49 PM
jay
jay - avatar
+ 2
if you are talking about the Increment and Decrement (++ or --) [https://www.sololearn.com/Discuss/774439/difference-between-prefix-a-and-postfix-a]
29th Oct 2017, 4:53 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
it is very easy.... prefix (++x) adds 1 to the valuee of x and then assigns to the X.... postfix (x++) uses value of x and then add 1 to the value of X.... here,, x=3; y=x; x++ will result in x=4... it will just change the value of itself accoriing to the condition above while in case of prefix.. x will be 4 and y will also be 4.... because here x has value for and according o the condition it will use its value and assing to y.. very simple...
29th Oct 2017, 5:41 PM
Muhammad Ali
Muhammad Ali - avatar
+ 1
But why in the example in the app x=14 and system.out.print(x++) output 14 and not 15 ? Can anyone explain to me , please ?
29th Oct 2017, 8:01 PM
Aymane El Boudali
Aymane El Boudali - avatar