himanshuhy004's blog

By himanshuhy004, history, 5 weeks ago, In English

Can someone please tell me why does this happen?

  • Vote: I like it
  • -9
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

First of all the code in the two submissions is not the same. However, fixing this difference does not explain the discrepancy.

The issue lies in the line else m[c] = --c, --k; which does a bunch of weird things including setting m[c] while modifying c in the middle of the expression, as well as using the comma operator.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In fact, after C++17, it wll first evaluate rhs then lhs so m[c] = --c is not UB...