0

Increment

Int x=1,y; so here what is the main difference between y=x++ and y=x+1 why one makes y=1 and second y=2

22nd Aug 2018, 1:34 PM
Muhammad Zubair
Muhammad Zubair - avatar
2 Respuestas
+ 1
Muhammad Zubair x++ is post increment... once you do y=x++;, two operations are done... first it assign value of x to y...so, y is 1 as of now... next, x is incremented as x=x+1 ...so, x becomes 2 and y remain 1... while in second case, simply we are adding value of x and 1 to y...so, y becomes 2
22nd Aug 2018, 1:49 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
22nd Aug 2018, 1:51 PM
Muhammad Zubair
Muhammad Zubair - avatar