代码如下:
#include <iostream>
using namespace std;
typedef struct person {
int id;
char sex;
static int count;
static long count2;
} person;
int main()
{
person a;
cout << sizeof(a) << endl;
cout << sizeof(person) << endl;
return 0;
}
输出:
8
8
分析:
int id;
char sex;
这两个就是一般的内存对齐;
但是对于static成员变量来说:
(没写完 时间太晚。。。。。后面补上)