Order of operations/precedence

Jul 16, 2013 at 4:32pm
could someone explain to me why the answer would be 3?

1
2
3
4
5
  int a = 5;
  
  a -= a-- - --a;

  cout << a;

Last edited on Jul 16, 2013 at 4:32pm
Jul 16, 2013 at 4:34pm
The code has undefined behaviour.
Jul 16, 2013 at 4:35pm
Are you saying its not valid? because its valid.
Jul 16, 2013 at 4:39pm
Jul 16, 2013 at 4:42pm
a -= a--(5) - --a(4-1)
5 -= 5 - 3
5 -= 2
3

http://stackoverflow.com/a/4706225/2089675

I have my doubts however that this is actually how it works, but if it does the way I showed is how it would be evaluated
Last edited on Jul 16, 2013 at 4:45pm
Topic archived. No new replies allowed.