0

[DUPLICATE] What is the diffrence between x++; and ++x; ?

I don't know exactly how it differs.

9th Mar 2018, 12:08 PM
ė°•ģ •ź·¼
ė°•ģ •ź·¼ - avatar
4 Answers
+ 5
++x increments the value of x and then returns x. x++ returns the value of x and then increments.
9th Mar 2018, 12:16 PM
Dread
Dread - avatar
+ 1
for x++ its work like if;ex: we have int x=1, y=0; y=x++; then; value of y = 1 (it's work like y=x then x=x+1) ---------------- for ++x its work like if;ex: we have int x=1, y=0; y=++x; then; value of y = 2 (it's work like x=x+1 then y=x) in both cases x becomes 2
9th Mar 2018, 12:17 PM
ajbura
ajbura - avatar
+ 1
x++ i.e post increment operator first assigns value then increments it. ++x i.e pre increment operator first increments value and then assigns it . a=5 b=a++ here, we get ,a=6 , b=5 a=5 b=++a here, we get ,a=6 , b=6
9th Mar 2018, 12:38 PM
Manorama
Manorama - avatar