注:类型 字节数
int 4
char 1
float 4
double 8
根据内存最大的数据的类型补齐内存,最后的内存数应该为其内存的整数倍,如:
1 int a; 2 char b;
则所占内存为8(4+1,再补齐为4的倍数8)
又如:
1 double a; 2 int b;
所占内存为16(8+4,再补齐为8的倍数16)
下面为实际的情况 ,可验证如上正确。
输出为:
例2:
输出为: