Evaluation of C expression

前端 未结 8 2086
南笙
南笙 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:24

    && and || use short-circuit evaluation, i.e. in the expression a&&b a is evaluated first, if it is false then the whole expression is false and b is not evaluated. In a||b if a is true then b is not evaluated. Note that if you overload && or || short-circuit rules will no longer apply. HTH

提交回复
热议问题