Блог пользователя himanshuhy004

Автор himanshuhy004, история, 6 недель назад, По-английски

Can someone please tell me why does this happen?

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

»
6 недель назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

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.

  • »
    »
    6 недель назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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