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 mean?
int arr[5];
sizeof(arr+0); // here array is converted to pointer
Why does the arithmetic on array is applied here?
(§ 5.3.3/4) The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and
function-to-pointer (4.3) standard conversions are not applied to the
operand of sizeof.
Best Answer
The sizeof() operator is calculated at compile time. The expressions are NOT evaluated. It is the type of the expression that is calculated (at compile time) and then used by sizeof().
So in your first one:
The type of x is int. The result of the += operator is still int. So the sizeof() is still the size of int.
In this:
Here arr is an array and would have returned the size of the array (if used by itself). But the operator + causes the array to decay into a pointer. The result of the + operator on an array and an integer is a pointer. So here the sizeof() operator will return the sizeof a pointer.
This means that:
But here:
As a side note:
This is why