Monday, May 24, 2010

For C language what is the difference b/w X-- or --X?

Can you provide some examples in the output?

For C language what is the difference b/w X-- or --X?
x-- means after the whole equation is solved then x is decremented.





--x is first decremented and then the equation is proceeds..





if


--x;


x--;


are just on a single line it doesn't matter if the decrementing is after or before the x because there is no other variable besides x but suppose:


y = 5;


x = 6


y = y + x--;


y would get 11. That decrementing would not make a difference on the present equation and after the equation is completed you x would get 5


y = y + --x; would get 10. hope that helps. the x is first decremented and then the equation is solved.
Reply:i++ will use the value of i in the statement and then increment





++i will increment i and then use the value in the statement





int i = 0;





cout %26lt;%26lt; i++; //Prints out 0 then adds 1 to i





//i == 1





cout %26lt;%26lt; ++i; //Prints 2 Increment, then print the value of i

yu gi oh cards

No comments:

Post a Comment