+ 7
Can some one properly explain difference between y = ++x and y = x++
5 odpowiedzi
+ 18
++x is prefix. x++ is postfix.
In the case of y =++x , y will become (x+1), x will become (x+1). Which means that prefix adds the value before processing the data/command.
However, in the case of y = x++ , y will become x and x will become (x+1).
Which also means that postfix process the data/command first before it adds the value.
+ 9
dude,consider y=1 and x=2 so when the condition is y = ++x first the computer will add 1 to the value of x and then give it to y, so the value of y becomes 3,and when there is y=x++ the value is first given to y and then 1 is added so in this condition value of y is 2. leave a like if you understood:-)
+ 4
thanks guys
+ 3
If we expand the operators :-
a = x++ //since plus is after x so we get
a = x
x = x+1
while for :
a = ++x (since x is later we have to assign later)
x = x+1
a = x (where x is increment so tenchically
a=x+1)
0
for example if you take x=5 &y=6
the answer will be y=6 & y =5
++x will increment the value by 1 with original value,
but in case of x++ the value of x is given to y and then it will increment by 1