0
What is difference between a = b++ and a = ++b
5 Answers
+ 2
the diferent is that by a=b++ a the value of b become and then inkrement. a=++b means tht before the valeue a get the value b will be inkremt and then assigned to a.
+ 1
thank you
+ 1
For a = b++, a would take the value of b first, then b += 1.
And a = ++b means that b += 1 first, then a take the value of b.
For example let b = 1,
after a = b++, a = 1 and b = 2;
but after a = ++b, a = 2 and b = 2.
+ 1
One is post increment (i++) the other is pre increment (++i)
lets say we have:
i=0;
//then de wish to do this addition
i=(i++) + (++i);
/* what happen...
1. i++ stays 0 as it is post increment.
2. i value becomes 1
3. ++i becomes 2 as it is pre increment.
4. the machine executes it as 0 + 2
5. finally the machine returns answer as 2*/
0
when b is 2
a=b++ // a is 2, b is 3
a=++b // a is equal to b and b is 3