+ 3
I do not understand the difference between pre and post increment/decrement. Tell me
4 Respuestas
+ 5
pre increment
i=0
++i bcm 1
post increment i=0
i++
used the i then increment in next iteration
+ 1
When
x = ++y
1st. y=y+1
2nd. x = y
When
x = y++
1st. x=y
2nd. y =y+1
+ 1
x=2
y=x++ (POSFIX) means that
y=2 and x=3
but if y=++x
y=3 and x=3 (PREFIX)
+ 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;
}