+ 1
What is difference between ++Ă and Ă++
4 Answers
+ 13
int x=5;
cout<<++x; //x=6 then outputs 6
x=5;
cout<<x++;//outputs 5 then x=6
so
++x increment then use
x++ use then increment
+ 3
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;
}
+ 1
++x is prefix increment
x++ is post increment
0
use than change and change than use