码迷,mamicode.com
首页 > 编程语言 > 详细

[C++] struct memory allocation

时间:2015-10-12 22:37:21      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

        Four-byte alignment

 1 typedef struct user  USER;
 2 typedef struct employee E;
 3 struct user{
 4 
 5     char name[10];  //take 12 bytes
 6     int age; //take 4 bytes
 7     short sex;//take 4 bytes
 8     char blood;//take 1 bytes but in  the 4 bytes of sex
 9 };
10 struct employee{
11 
12     char name[5];  //take 8 bytes
13     int age; //take 4 bytes
14     char blood;//take 4 bytes 
15 };
16 int main(){
17 
18     printf("%d\n", sizeof(USER));// 12+4+4
19     printf("%d\n", sizeof(E));// 8+4+4
20     system("pause");
21 }

 

[C++] struct memory allocation

标签:

原文地址:http://www.cnblogs.com/tianhangzhang/p/4872834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!