-4

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?

Abhishek
  • 1
  • 2

1 Answers1

0

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.

Lala5th
  • 1,137
  • 7
  • 18