+ 1
Prefix and postfix
x++ and ++x have a difference I can't understand it
8 Answers
+ 4
Have you tried searching the q&a? This question gets asked almost everyday.
+ 3
int x = 2,y = 2;
cout << x++; //prints 2
cout << ++y; //prints 3
+ 2
++x increments x value before anything.
x++ increments x after the statement.
int x=0, a;
a=x++;// Same as a=x; x=x+1; So a=0.
a=++x;// Same as x=x+1; a=x; So a=1.
Ask if you don't understand..
+ 1
thanks now I understand it
+ 1
suppose
x= 3
cout<<x++; //it will print x=3 and then value of x will be incremented to 4
cout<<++x. //the value of x is incremented to 4 and then will be printed as x=4
+ 1
Yes, They have a difference. check this code
https://code.sololearn.com/c1QiIY7I27Kx/?ref=app
0
no I didn't check