In C++, the expressions inside sizeof
is not evaluated, except for C99’s VLA as mentioned in comments, since this was earlier tagged for C too
The sizeof
operator is calculated at compile time.
Only the type of the expression (that is calculated at compile time) is then used by sizeof
.
From C++ Standard § 5.3.3 Sizeof
The sizeof operator yields the number of bytes in the object
representation of its operand. The operand is either an expression,
which is an unevaluated operand (Clause 5), or a parenthesized
type-id.
Some C++ compilers provide VLAs as an extension as commented below.