- 1

Whats the difference between ++x, and x++... How do they work? And kindly give examples and challenges to test if i understand

C++

19th Sep 2017, 4:55 AM
Nduta
Nduta - avatar
5 Respostas
+ 1
let x = 1 the x++ \\ first assign then increment. after assign x = 2 x=1 ++x = 2 \\ first increment then assign x = 2
19th Sep 2017, 5:00 AM
kanishk goel
kanishk goel - avatar
0
hi Nduta, x=0 y=x++ like y=x and x=x+1 then y=0 and x=0+1=1 so z=x++ like z=x and x=x+1 then z=1 and x=1+1=2 a=4 b=++a like a=a+x and b=a then a=4+1=5 and b=5 i hope that will be ok bye
19th Sep 2017, 6:24 AM
MBZH31
MBZH31 - avatar
0
Hi @MBZH31 i dont understand the last part of it. Where a=4 Then b=++a
20th Sep 2017, 4:54 AM
Nduta
Nduta - avatar
0
hi, it's an other example with a and b instead of x and y if you want, replace a by x and b by y. in this part, we do an increment of a before to initialyse b
20th Sep 2017, 5:49 AM
MBZH31
MBZH31 - avatar