typedef struct _MyStruct
{
int a;
int b;
int c;
_MyStruct() { a = 0; b = 0; c = 0; }
}MyStruct;
int main()
{
#if 1
MyStruct* st[3]; //数组指针
MyStruct* str = new MyStruct;
st[0] = str;
cout << st << endl; //0x00D3F7BC
cout << st+1 << endl; //0x00D3F7C0 //偏移4
cout << (*st) << endl; //0x01326328
cout << (*st)+1 << endl; //0x01326334 //偏移1*sizeof(MyStruct)
int size = sizeof(st); //12 //sizeof(MyStruct)
int size2 = sizeof(st + 1); //4
int size3 = sizeof((*st)); //4
int size4 = sizeof((*st) + 1); //4
#endif
#if 1
MyStruct st[2][3]; //二维数组
MyStruct* str = new MyStruct;
st[0][0] = *str;
cout << st << endl; //0x001BF9AC
cout << st+1 << endl; //0x001BF9D0 //偏移3*sizeof(MyStruct)
cout << (*st) << endl; //0x001BF9AC
cout << (*st)+1 << endl; //0x001BF9B8 //偏移1*sizeof(MyStruct)
int size = sizeof(st); //72 //2*3*sizeof(MyStruct)
int size2 = sizeof(st + 1); //4
int size3 = sizeof((*st)); //36 //3*sizeof(MyStruct)
int size4 = sizeof((*st) + 1); //4
#endif
return 0;
}
标签:str,int,MyStruct,C++,累加,偏移量,数组,指针
From: https://www.cnblogs.com/Brickert/p/16730482.html