In which order are the increment expressions on the right evaluated in the assignment statement? Is it undefined?

前端 未结 1 409
醉话见心
醉话见心 2021-01-16 11:45

I recently learnt about undefined behaviour in C, but this particular code was used in a site as an example for \'comma as an operator\', and while I understand how y = x++

相关标签:
1条回答
  • 2021-01-16 12:17

    It is not undefined behaviour.
    You first increase x to 11, the print it, then increase it to 12 and print it, then increase it after evaluation, so x will be 13 and the whole expression will evaluate to 12.

    This is caused due to the comma operator in C being a sequence point, which means it is guaranteed all side effects of previous evaluations will have been performed, and no side effect from subsequent evaluations have yet been performed.

    0 讨论(0)
提交回复
热议问题