重複の可能性:
構造体パディング
プログラムは以下の通りです。
#include <iostream>
using namespace std;
struct node1 {
int id;
char name[4];
};
struct node2 {
int id;
char name[3];
};
int
main(int argc, char* argv[])
{
cout << sizeof(struct node1) << endl;
cout << sizeof(struct node2) << endl;
return 0;
}
そしてコンパイラはg++ (GCC) 4.6.3
です。出力は次のとおりです。
8
8
なぜそうなのか本当にわかりません。なぜsizeof(struct node2)
7ではないのですか?