Possible Duplicate:
Struct Padding
The program is as below:
#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;
}
And the compiler is g++ (GCC) 4.6.3
. The outputs are:
8
8
I really do not understand why is it so. Why is the output of sizeof(struct node2)
not 7?