Why does
int a, b = 10;
b = b++;
printf ("%d", b);
output 10
while
int a, b = 10;
a = b++;
printf ("%d", b);
outputs 11
how does this work? Why doesn't 'b' increment in first case?
Why does
int a, b = 10;
b = b++;
printf ("%d", b);
output 10
while
int a, b = 10;
a = b++;
printf ("%d", b);
outputs 11
how does this work? Why doesn't 'b' increment in first case?
b++ performs assignment with not-incremented value while ++b would do assignment with the incremented value. You only need b++; in your code without assignment to increment. As someone also pointed out b = b++; and b = ++b; are not good segments of code and you are at the mercy of the compiler.