Considering :
double data;
double array[10];
std::vector vec(4, 100);
MyClass myclass;
Is there a difference between :
Whenever you use sizeof(
, it is always evaluated at compile time. It is the datatype of the parameter that sizeof
is concerned with.
However, you can pass values, and even expressions as parameter. But the sizeof function will only consider the dataype of the passed parameter.
You can also pass expressions as sizeof(x = x+1);
. Say x
was int. In this case this sizeof
will return 4
(as on my machine) and the value of x will remain unchanged. This is because sizeof
is always evaluated at compile time.
The two set of syntax you provide, will return the same result, but you cannot say they are equivalent. But yes, latter is defined in terms of former.