sizeof operands get evaluated?

后端 未结 3 1752
生来不讨喜
生来不讨喜 2020-12-19 02:14

AFAIK sizeof doesn\'t evaluate its operands it C++.

E.g.

int x = 0;
sizeof(x += 1); // value of x is not changed

But what does this

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 02:42

    I don't know much about this, but if as you say, sizeof doesn't evaluate its operand then it must just rely on the type of the expression it's used on. So I would guess that arr on its own has a different type to arr+0, and that's why it was used.

提交回复
热议问题