// 结构体大小计算的例子 // 默认对齐数为4 #include <stdio.h> union tagAAA { struct { char ucFirst;//1 short ucSecond;//2 char ucThird;//1 }half; short kk;//2 }number; struct tagBBB { char ucFirst;//1 short ucSecond;//2 char ucThird;//1 short ucForth;//2 }half; struct tagCCC { struct { char ucFirst;//1 short ucSecond;//2 char ucThird;//1 }half; long kk;//4 }; int main() { printf("%d\n", sizeof(union tagAAA)); printf("%d\n", sizeof(struct tagBBB)); printf("%d\n", sizeof(struct tagCCC)); return 0; } <img src="http://img.blog.csdn.net/20150511150317650?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
时间: 2024-11-09 18:25:25