C语言结构体的字节对齐

Test Code:

 #include <iostream>
#include <cstring> using namespace std; struct A{
int a;
short b;
char d;
char e[];
}; struct B{
int a;
short b;
char *c;
char d;
char e[];
}; 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 ; }

Output(Fedora 64bit):

20
32
short 2
int 4
long 8
char* 8
上一篇:【转载】最强NLP预训练模型!谷歌BERT横扫11项NLP任务记录


下一篇:ifconfig 工具