0

What is the difference between x++ and ++x

28th Sep 2016, 5:04 PM
nateelectroman
5 Answers
+ 3
x++ is post increment i.e.,the value of x is assigned first and then incremented. where as ++x is pre increment i.e., the value of x is first incremented and then assigned to x.
28th Sep 2016, 5:59 PM
siddharth jadhav
siddharth jadhav - avatar
+ 2
x++: First evaluate X and then add 1. ++X: First add 1 to X and then evaluate.
28th Sep 2016, 5:57 PM
ABC
ABC - avatar
+ 2
The main difference is that in x++ the value of x gets incremented after using it's initial value one time in the expression While ++x first increments then uses it's value
11th Aug 2019, 7:32 AM
Reca Resu
Reca Resu - avatar
+ 1
You have it right. The only difference is the order in which the increase happens. For example: If X = 4 and Y = 4, cout << x++; //Prints 4 and then X increases. cout << ++Y; //Y increases and then prints 5.
28th Sep 2016, 7:08 PM
ABC
ABC - avatar
- 1
Question, so 4++ = 5 and ++4= 5 or do i have it wrong
28th Sep 2016, 7:03 PM
Christian Dior
Christian Dior - avatar