i = i++ + ++i
How to solve it?
i = i++ + ++i
How to solve it?
Hi @ssinha2103
lets consider a test case… let initially i be 2…
now u are performing i = i++ + ++i;
so when i++ is performed it is post increment… which means initially value of i remains same and is used for computation and then value of i is incremented by 1… so in my ans 2 would be added and i becomes 3…
now when ++i is performed it means pre increment, ie increase value of i by 1 first then use it for computation… thus i becomes 4… now when u add it to our ans 2 + 4 comes out to be 6 and that value is assisgned to i varible…
u can also try running the same code in ide with test case 2, u will get the same ans ie 6…
i hope it clears all ur doubts…
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.