C中sizeof(struct structname)和sizeof(object)之间的区别

him*_*dri 3 c sizeof

是否有场景中可以有差异之间sizeof(struct structure_name)sizeof(object)其中object的类型是struct structure_name用C?

Jar*_*Par 7

没有有什么区别sizeof(type),并sizeof(o)声明的类型otype.

如果对象的声明类型不能真正代表对象,则可能存在差异.例如

char arrayValue[100];
sizeof(arrayValue);  // 100 on most systems
char* pointerValue = arrayValue;
sizeof(pointerValue);  // 4 on most 32 bit systems
Run Code Online (Sandbox Code Playgroud)

之所以出现这种差异,是因为它sizeof是C语言中的编译时构造.因此,没有运行时分析,编译器会查看静态声明的类型.