Some operators do not evaluate their operands beyond the type information they provide. When using one of these operators, do not pass an operand which would otherwise yield a side effect, as the side effect will not be generated.
The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. In most cases, the operand is not evaluated. A possible exception is when the type of the operand is a variable length array type (VLA) the expression is evaluated. When part of the operand of the sizeof operator is a VLA type and when changing the value of the VLA's size expression would not affect the result of the operator, it is unspecified whether or not the size expression is evaluated. See unspecified behavior 22 in Annex J of the C Standard.
...
In this noncompliant code example, the expression ++n
in the initialization expression of a
must be evaluated because its value affects the size of the VLA operand of the sizeof
operator. However, in the initialization expressino expression of b
, the expression ++n % 1
evaluates to 0.
This means that the value of n
does not affect the result of the sizeof
operator. Consequently, it is unspecified whether or not n
will be incremented when initializing b
.
...