sizeof operands get evaluated?

后端 未结 3 1753
生来不讨喜
生来不讨喜 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:32

    It isn’t. In an arithmetic expression, array names decay into pointers. That says nothing about performing the calculation itself. The type of + is deducible from the types of its operands, in this case pointer and integer, yielding the same result as sizeof(int*).

提交回复
热议问题