1

I am wondering if following expression has defined behavior (always equal to "a=n/(n+1); ++n;") in C++?

a=n/++n;
Tudor
  • 61,523
  • 12
  • 102
  • 142
poordeveloper
  • 2,272
  • 1
  • 23
  • 36
  • 1
    Unless this is for academic purposes, why would you want to write something that is difficult or ambiguous to understand ? – ereOn Jan 13 '12 at 08:49
  • See [Undefined Behavior and Sequence Points](http://stackoverflow.com/questions/4176328/). – outis Jan 13 '12 at 08:55
  • Voted to reopen to close as dupe of @outis' linked question. – Xeo Jan 13 '12 at 10:20

1 Answers1

3

It's undefined. You cannot both modify and access a variable without either having an intervening sequence point or using a single access/modify operator.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278