Prefix and postfix | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Prefix and postfix

x++ and ++x have a difference I can't understand it

10th Jul 2017, 7:07 AM
Abhishek Powar
Abhishek Powar - avatar
8 Answers
10th Jul 2017, 8:07 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Have you tried searching the q&a? This question gets asked almost everyday.
10th Jul 2017, 7:15 AM
Bagshot
Bagshot - avatar
+ 3
int x = 2,y = 2; cout << x++; //prints 2 cout << ++y; //prints 3
10th Jul 2017, 7:19 AM
johan beimers
johan beimers - avatar
+ 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..
10th Jul 2017, 7:18 AM
Jojo
+ 1
thanks now I understand it
10th Jul 2017, 7:19 AM
Abhishek Powar
Abhishek Powar - avatar
+ 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
10th Jul 2017, 7:39 AM
Rishabh Singh Rajput
Rishabh Singh Rajput - avatar
+ 1
Yes, They have a difference. check this code https://code.sololearn.com/c1QiIY7I27Kx/?ref=app
11th May 2020, 12:23 PM
Aayushi Mittal
Aayushi Mittal - avatar
0
no I didn't check
10th Jul 2017, 7:15 AM
Abhishek Powar
Abhishek Powar - avatar