+ 1

Can someone explain the difference between x++ and ++x for me in a dumb way? thanks!

I really don't get why you need ++x

14th Jul 2016, 1:07 AM
Eyad Alfaleh
Eyad Alfaleh - avatar
10 Antworten
+ 7
x++ use the value stored in x and then do x = x +1 ++x do x = x + 1 and then use the new value stored in x in the rest of the statement... Putting all together in an example: x = 1; y = ++x; // you will have y = 2 and x = 2 z = x++; // now you will have z = 2 and x = 3
14th Jul 2016, 1:56 AM
Nelson Urbina
Nelson Urbina - avatar
+ 2
int x=5; cout<<x++; //5 int x=5; cout<<++x; //6 however, int x=5; x++; cout<<x; //6
15th Jul 2016, 4:30 AM
Rohit Sarkar
Rohit Sarkar - avatar
0
x++ is a like to 1 and ++x is a call time value is 1
14th Jul 2016, 1:43 AM
ankit mishra
ankit mishra - avatar
0
x++ is a postfix operator and the value of x is incremented later. ++x is a prefix operator which first increments the value of x by 1. Lets take an example x=5; sum=++x + x++ ;
14th Jul 2016, 3:02 AM
Programmer
0
so its output will be 6 + 6 = 12. so 12 will be stored in sum. Got it !!
14th Jul 2016, 3:04 AM
Programmer
0
plz explian me also
14th Jul 2016, 5:34 AM
Fawad Qureshi
Fawad Qureshi - avatar
0
yeah as above said 😉😉
15th Jul 2016, 6:28 AM
Divij Nagendra
Divij Nagendra - avatar
0
x = 1 y = ++x y = (x = x+1) This causes: x = x+1 y = x [x = 2, y = 2] y = x++ y = x, x = x+1 This means: x = 1 y = x x = x+1 [x = 2, y =1]
7th Oct 2016, 3:00 PM
Chese780 ~
Chese780 ~ - avatar
- 1
Explain it to yourself. Enter a value of x then cout it. then use ++x and again cout <<x and for the last time use x++ and cout<<x again.
14th Jul 2016, 5:36 PM
Somesh Narwade
Somesh Narwade - avatar
- 1
the ++a and a++ is a+1 so the two are same
17th Jul 2016, 2:50 AM
Aswath