Conditional operator “ ? : ”

后端 未结 3 1315
盖世英雄少女心
盖世英雄少女心 2021-01-13 18:24

I\'ve done my programming exam in C yesterday. There was a question I could not answer, and even though I\'ve studied today I can\'t come up with a solution.

So we h

3条回答
  •  野的像风
    2021-01-13 19:21

    This question should never be on an exam, because it contains undefined behavior.

    Specifically, this assignment A = (~C) - A-- modifies A twice - in the -- compound assignment, and in the assignment itself. Since there is no sequence point in between the two, the behavior is undefined.

    Note: This does not mean that the program is not going to print anything. It would most definitely produce some output on most platforms. However, none of that matters, because C the program is invalid in its entirety: it can produce any output it chooses to, produce no output, or even crash.

提交回复
热议问题