您的位置:首页 > 编程语言 > C语言/C++

C语言结构体的字节对齐

2016-04-18 10:35 274 查看
Test Code:

#include <iostream>
#include <cstring>

using namespace std;

struct A{
int a;
short b;
char d;
char e[10];
};

struct B{
int a;
short b;
char *c;
char d;
char e[10];
};

int main(){

cout<<sizeof(A)<<endl;
cout<<sizeof(B)<<endl;
cout<<"short "<<sizeof(short)<<endl;
cout<<"int "<<sizeof(int)<<endl;
cout<<"long "<<sizeof(long)<<endl;
cout<<"char* "<<sizeof(char*)<<endl;

return 0;

}


Output(Fedora 64bit):

20
32
short 2
int 4
long 8
char* 8
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: