himanshuhy004's blog

By himanshuhy004, history, 12 days ago, In English

Can someone please tell me why does this happen?

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

»
11 days 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.

  • »
    »
    11 days 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...