1
유니온 구성원이 메모리 공간을 공유한다는 것을 알고 있으므로 다음 코드가 9 & 9를 출력 할 것으로 기대합니다. 그러나 12 & 9. 왜?C++ struct의 이상한 동작
union Sample_union {
int x;
char array [9];
};
int main(){
Sample_union sample;
cout<<sizeof(sample)<<endl;
char test [9];
cout<<sizeof(test)<<endl;
}
다른 컴파일러에서도 다음 코드를 테스트합니다.
'struct','class' 및'union'의 데이터 멤버가 _padded_ 될 수 있기 때문에. –