- 1
Whats the difference between ++x, and x++... How do they work? And kindly give examples and challenges to test if i understand
C++
5 odpowiedzi
+ 1
let x = 1 the
x++ \\ first assign then increment.
after assign x = 2
x=1
++x = 2 \\ first increment then assign
x = 2
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
0
Hi @MBZH31 i dont understand the last part of it. Where a=4
Then b=++a
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