+ 2
i see the postfix x=5; y=x++; //x is 6,y is 5 so my question is that why x is 6 not 5 and y is 5 not 6??
4 Antworten
+ 7
By writting x++, your basically saying to the console to add 1 to the value of x AFTER it gives it to y, thats why(lol the pun) it says that x has a value of 6 and y a value of 5. When you put x++ or ++x, on the first form, it adds the value (1) AFTER it does the operation (in this case, giving the same value to y making it x=6 and y =5 ) while on the second form, the value is added BEFORE the operation is performed(resulting in x=6 and y =6). Hope it helps. Return 0;
+ 2
++ is applied to x, not y.
+ 1
Y=X++ is postfix operation which means 1) value of x is returned first and assigned to y. Hence y=5
2) then x is incremented. Hence x becomes 6
- 2
djdj