0
What is the difference between x++ and ++x
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.
+ 2
x++: First evaluate X and then add 1.
++X: First add 1 to X and then evaluate.
+ 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
+ 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.
- 1
Question, so 4++ = 5 and ++4= 5 or do i have it wrong