Evaluation of C expression

前端 未结 8 2091
南笙
南笙 2020-12-11 18:01
int main() {
  int i = -3, j = 2,  k = 0, m;
  m = ++i || ++j && ++k;
  printf(\"%d %d %d %d\\n\", i, j, k, m);
  return 0;
}

i thought tha

8条回答
  •  余生分开走
    2020-12-11 18:14

    && does have higher precedence than ||, which means that ++i || ++j && ++k parses as ++i || (++j && ++k).

    However this does not change the fact that the RHS of || only executes if the LHS returns 0.

    Precedence does not affect order of evaluation.

提交回复
热议问题