typedef:定义类型,给一种数据类型起别名
结构体大小: 内存对齐:每个人数据存放的内存地址,能整除数据本身的大小(快速 1、前面所有成员的字节数能整除当前成员大小 2、结构体的大小必须能整除单个最大类型的大小
#include<stdio.h> #include<string.h> typedef struct A { float a;//4 int b;//4 }A;//8 typedef struct B { char c;//1+3 int d;//4 }B;//8 typedef struct C { char a;//1+1 short b;//2 int c;//4 }C;//8 typedef struct D { char a;//1+3 int b;//4 long *c;//4+4 double d; }D;//24 typedef struct F { int a;//4 char b;//1 }F;//5+3 typedef struct G { char a;//1+3 int b;//4 short c;//2 }G;//10+2 typedef struct HH { char a;//1+3 int b;//4 }HH;//8 typedef struct H { int c;//4 struct HH d;//8 double d; } H;//12 int main() { printf("%d\n",sizeof(struct A)); printf("%d\n",sizeof(struct B)); printf("%d\n",sizeof(struct C)); return 0; }