Last Updated: February 25, 2016
·
1.675K
· alexanderbrevig

Post increment gotcha

Try to answer this without testing:

c=2;
c = 1 + c++;
// c = 3 or 4 ?

Compare it to:

c=2;
c = 1 + (++c);
// c = 3 or 4 ?

Finally:

c=[1,2,3];
i = 1;
c[i] = i++:
// c[1] = 1 or 2, or c[2] = 2 ?

1 Response
Add your response

i enjoyed this brain exercise! a very original tip -- kudos.

over 1 year ago ·