0

++X and X++

What is the main difference between the ++X and X++

3rd Jun 2017, 2:44 PM
Rachit Tripathi 😘
Rachit Tripathi 😘 - avatar
1 ответ
+ 1
result of both lines is same when a statement has only one of these. like x++; and ++x; both increases the value of x by 1. But when u use them together with other operations then there is a difference.Suppose x=5; y=5+(x++); Here value of x is added to 5 then it is increased so y=5+5; result is 10(post(after)-increment:first use the value then increment). Here y=5+(++x). x is incremented first then added to 5(pre(before)-increment: first increase then use the value) so y= 5+6;
3rd Jun 2017, 3:00 PM
Sushilkumar Shinde
Sushilkumar Shinde - avatar