-1

after the operation, b should equal to 5, then be should post decrement resulting b = 5, can anyone explain why this is not happening?

#include <stdio.h>

void main()
{
   int a =2, b=3;
   b=a++ + b--;
   printf("a=%d  b=%d\n", a, b);
}
Sai Kadali
  • 13
  • 4

1 Answers1

0

you are attempting to change b twice in the same expression

b = <something>;    // change b
    /*   b--  */    // change b

The order of the changes is not specified.

pmg
  • 106,608
  • 13
  • 126
  • 198