sizeof(struct)...给出错误的结果,VS 2010

时间:2013-12-01 17:02:24

标签: c++ structure sizeof

struct test{
    int year;
    char text;
    double num;
};

int main ()
{

 test t;
 cout<<sizeof(t);
  return 0;
}

结果是16,而我期待13.因为sizeof(char)是1.我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

C ++可以在成员之间添加填充。因此,结构可能大于其成员的添加大小。

相关问题