About how the increment works | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

About how the increment works

I cant understand ho x = 3, y = ++x .. outputs as x=4 and y=4

11th Oct 2018, 1:40 PM
Carl Marion Manlapaz
Carl Marion Manlapaz - avatar
3 Answers
+ 1
well x is incremented by one (x =4) then is assigned to y ( then y = 4)... note that if used post-increment happen opposite: first x is assigned to y (then y=3) next x is incremented (then x=4)
11th Oct 2018, 1:46 PM
KrOW
KrOW - avatar
0
Because it's a prefix increment, so the value of x gets incremented to 4 and then y gets assigned to that value. Alternatively, x++ will assign 3 to y and then increment x to 4 after.
11th Oct 2018, 1:46 PM
Voxel
Voxel - avatar
0
thank you for the fast response. really helpful
11th Oct 2018, 1:49 PM
Carl Marion Manlapaz
Carl Marion Manlapaz - avatar