#include <iostream>
using namespace std;
struct Rectangle
{
int length;
int breath;
char x;
};
int main()
{
struct Rectangle r1 = { 10,5 };
cout << sizeof(r1) << endl;
//9byte가 나오기를 예상했으나, 컴파일러는 char를 4byte로 할당함
//그러나 메모리 사용은 1byte만 함
r1.length = 15;
r1.breath = 7;
cout << r1.length << endl;
cout << r1.breath << endl;
return 0;
}
sizeof(r1.x)를 하면 1byte가 나오지만, sizeof(r1)을 하면 12byte가 나오는데, 그 이유는 컴파일러는 구조체를 한번에 4byte로 읽기 쉬워서 그렇다.