Quite confused about ++x and x++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Quite confused about ++x and x++

27th Jul 2016, 2:51 PM
Aikansh Boyal
Aikansh Boyal - avatar
2 Answers
+ 6
++x increments the value of x first , then solve the equation x++ solves the equation first then increments the value of x
27th Jul 2016, 3:57 PM
Karan Luther
Karan Luther - avatar
+ 5
++x is a pre increment operator which first increments the value of x and then uses it in the program where x++ is a post increment operator which first uses the value of x and then increments its value. For eg. int a=2; cout<<a++; prints 2 and then it increments a's value by 1. As soon as it prints 2, a's value will be 3. If we use 'a' again after that cout statement, its value will be 3. whereas cout<<++a increments its value first and prints 3. Hope it helps.
27th Jul 2016, 3:38 PM
Balaji V
Balaji V - avatar