0

Trying to better understand the following. Before each statement I assign a=5;

  1. ++a=1+a++; // a is 6 now
  2. a=a+1+a++; // a is 11 now
  3. a+=1+a++; // a is 12 now
  4. ++a+=1+a++; // a is 13 now

Can someone explain the execution order to get these results or point to some examples/documentation? Thank you. I get what needs to happen to get these results, trying to gain a deeper understanding of the rules.

Peter Green
  • 25
  • 1
  • 6
  • 1
    Before C++17, you have UB. For after, read https://en.cppreference.com/w/cpp/language/eval_order (item 20)) – Jarod42 Aug 02 '20 at 10:41
  • And [evaluation order](https://en.cppreference.com/w/cpp/language/eval_order) so `++a = b` is `(++a) = b` and not `++(a = b)`. – Jarod42 Aug 02 '20 at 10:51

0 Answers0