#include <stdio.h>
struct people
{
int d;
int f;
short g;
};
struct student : public people
{
int a;
int b;
int c;
};
int main( )
{
student* a;
a=(student*)0;
printf("%d\n",(int)&(a)->f) ;
printf("%d\n",(int)&((student*)0)->g) ;
return 0;
}
计算结构体各成员的偏移
于 2022-01-19 18:01:09 首次发布
本文通过一个C++示例程序展示了如何使用结构体和继承,并计算成员变量的内存偏移量。这对于理解C++中内存布局和结构体对齐规则非常有用。
1415

被折叠的 条评论
为什么被折叠?



