比这篇新的文章: Codee#2280
比这篇旧的文章: Codee#2278

计算机结构体大小

语言: C++, 标签: 无  2009/06/18发布 9个月前更新
作者: 邓晓华, 点击152次, 评论(0), 收藏者(0), , 打分:

背景
主题: 字体:
01 #include <stdio.h>   
02   
03 struct stu   
04 {   
05     int i;   
06     char c;   
07     int k;   
08 };  //大小为12   
09   
10 struct stu_2   
11 {   
12     int k;   
13     short t;   
14 };  //大小为8   
15   
16 struct stu_3   
17 {   
18     char c1;   
19     int i;   
20     char c2;   
21 };  //大小为12   
22   
23 struct stu_4   
24 {   
25     char c1;   
26     char c2;   
27     int i;   
28 };  //大小为8   
29   
30 struct stu_5   
31 {   
32     short i;   
33     struct  
34     {   
35         char c;   
36         int j;   
37     }ss;   
38     int k;   
39 };  //大小为16   
40   
41 int main(void)   
42 {   
43     int a, b, c, d, e;   
44   
45     a = sizeof(struct stu);   
46     b = sizeof(struct stu_2);   
47     c = sizeof(struct stu_3);   
48     d = sizeof(struct stu_4);   
49     e = sizeof(struct stu_5);   
50     printf("size of struct stu   = %d\n", a);   //12   
51     printf("size of struct stu_2 = %d\n", b);   //8   
52     printf("size of struct stu_3 = %d\n", c);   //12   
53     printf("size of struct stu_4 = %d\n", d);   //8   
54     printf("size of struct stu_5 = %d\n", e);   //16   
55     return 0;   
56 }


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论