0
該方案如下:
#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?
'node2' has padding – Musa