Are there scenarios where there can be a difference between sizeof(struct structure_name)
and sizeof(object)
where object
is of type struct structure_name
in C?
No there is no difference between sizeof(type)
and sizeof(o)
where the declared type of o
is type
.
There can be differences if the declared type of the object isn't truly representative of the object. For example
char arrayValue[100];
sizeof(arrayValue); // 100 on most systems
char* pointerValue = arrayValue;
sizeof(pointerValue); // 4 on most 32 bit systems
This difference occurs because sizeof
is a compile time construct in C. Hence there is no runtime analysis and the compiler looks instead at the statically declared types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With