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

C语言结构体的字节对齐

时间:2016-04-18 11:29:37      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

Test Code:

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 using namespace std;
 5 
 6 struct A{
 7     int a;
 8     short b;
 9     char d;
10     char e[10];
11 };
12 
13 struct B{
14     int a;
15     short b;
16     char *c;
17     char d;
18     char e[10];
19 };
20 
21 int main(){
22 
23     cout<<sizeof(A)<<endl;
24     cout<<sizeof(B)<<endl;
25     cout<<"short "<<sizeof(short)<<endl;
26     cout<<"int "<<sizeof(int)<<endl;
27     cout<<"long "<<sizeof(long)<<endl;
28     cout<<"char* "<<sizeof(char*)<<endl;
29 
30     return 0;
31 
32 }

Output(Fedora 64bit):

20
32
short 2
int 4
long 8
char* 8

 

C语言结构体的字节对齐

标签:

原文地址:http://www.cnblogs.com/hu983/p/5403508.html

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