结构的存储分配(c和指针.P206.)

来源:互联网 发布:php打包文件夹 zip 编辑:程序博客网 时间:2024/05/23 00:05


#include<stdio.h>

#include<stddef.h>

 

int main()

{

    struct ALIGN

         {

                   char a;

                   int  b;

                   char c;

         };

 

         struct ALIGN1

         {

             int b;

                   char a;

                   char c;

         };

 

         printf("      sizeof(struct ALIGN) =%d\n",sizeof(struct ALIGN) );

         printf("offsetof(struct ALIGN, a) = %d\n", offsetof(struct ALIGN, a));

         printf("offsetof(struct ALIGN, b) = %d\n", offsetof(struct ALIGN, b));

         printf("offsetof(struct ALIGN, c) = %d\n", offsetof(struct ALIGN, c));

 

         printf("      sizeof(struct ALIGN1) =%d\n",sizeof(struct ALIGN1) );

         printf("offsetof(struct ALIGN1, b) = %d\n", offsetof(struct ALIGN1, b));

         printf("offsetof(struct ALIGN1, a) = %d\n", offsetof(struct ALIGN1, a));

         printf("offsetof(struct ALIGN1, c) = %d\n", offsetof(struct ALIGN1, c));

 

    getchar();

         return 0;

}
运行结果为:
























原创粉丝点击