Considering :
double data;
double array[10];
std::vector vec(4, 100);
MyClass myclass;
Is there a difference between :
The latter is defined in terms of the former. Given an expression, it returns the size of the type of the expression. So sizeof(vec)
translates to sizeof(std::vector
.
Both are evaluated at compile-time; the only run-time sizeof
is in C, not C++, with variable-length arrays. The operand to sizeof
is unevaluated, so there isn't any real possibly the expression itself could generate code anyway.
I prefer to use expressions over types, because chances are stating the type is redundant in some fashion.