您的位置:首页 > 其它

结构体偏移量

2015-08-10 11:38 274 查看
typedef struct {
char id[64];
char *name;
}Student3;
void main()
{
//    int i = 0;
Student3 *p = NULL;
Student3  t1; // & (t1.age)

p = &t1;
//p = p + 100;
//strcpy(0, "dddd");
//p - 1 ; //编译通过 运行通过 这句话 在cpu中计算
//p - 2;
//p - 3;

{
int offsize1 =   (int)&(p->name) - (int)p; // & (t1.age)
int offsize2 = (int )&(((Student3 *)0)->name );
printf("offsize1:%d \n", offsize1);
printf("offsize2:%d \n", offsize2);

}

printf("hello...\n");
system("pause");
return ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: