您的位置:首页 > 其它

获取成员变量的地址和偏移地址

2016-03-10 17:15 330 查看
#include<iostream>
using namespace std;

struct Point3D{
int a;
int b;
int c;
};

int main(){

Point3D *p = NULL;
int offset = (int)(&(p)->c);
int i = (int)(&(p->c));
cout << &(p->c) << endl;
cout << i << endl;

cout << offset << endl;
cout << "............" << endl;
int j = (int)(&(*p).c);
cout << j << endl;

Point3D p3d;
int k = (int)(&p3d.c);
cout << k << endl;

return 0;

}

$ ./a
0x8
8
8
............
8
2686712


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: