Regardless of whether sizeof
is computed at compile time or runtime (or more formally speaking, whether its result is an integer constant expression), the result of sizeof
is purely based on the type of its argument and not any hidden data accompanying the variable-length array itself. Of course when sizeof
is applied to a variably-modified type, the generated program must keep track of that size somewhere. But it might simply recompute it if the expression was simple enough and the variables it originally derived the length from cannot have changed. Or, it could store the size of the type somewhere (essentially in a hidden local variable), but this would not be connected to the VLA object in any observable way (for example, if you pass a pointer to the first element of the VLA to another function, that pointer cannot be used to recover the VLA length).