I do not understand the difference between pre and post increment/decrement. Tell me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

I do not understand the difference between pre and post increment/decrement. Tell me

28th Oct 2016, 3:50 PM
Shruti Singh
Shruti Singh - avatar
4 Answers
+ 5
pre increment i=0 ++i bcm 1 post increment i=0 i++ used the i then increment in next iteration
9th Feb 2018, 7:13 PM
sarvesh hardikar
sarvesh hardikar - avatar
+ 1
When x = ++y 1st. y=y+1 2nd. x = y When x = y++ 1st. x=y 2nd. y =y+1
28th Oct 2016, 3:57 PM
Juan Luis García
Juan Luis García - avatar
+ 1
x=2 y=x++ (POSFIX) means that y=2 and x=3 but if y=++x y=3 and x=3 (PREFIX)
29th Oct 2016, 10:22 PM
Mamadou Lamine Tall
Mamadou Lamine Tall - avatar
+ 1
x++ Use the variable and afer that, it increase its value ++x Increase the value of the variable, after that use if Example 1 ---------- (Displays "Msg1, value of x=2") int x = 1; if (x++==1){ cout<<"Msg1, value of x="<<x; } else{ cout<<"Msg2values of x="<<x; } Example 2 ---------- (Displays "Msg2, value of x=2") int x = 1; if (++x==1){ cout<<"Msg1, value of x="<<x; } else{ cout<<"Msg2values of x="<<x; }
4th Nov 2016, 1:33 PM
Leruli Benavides
Leruli Benavides - avatar