【13】如何计算一个结构体需要多少字节的长度

struct A
{
    int a;
    float b;
};//8  

由于int四个字节,float四个字节,所以八个字节

struct B
{
    char a;//1+3
    int b;//4
};//8

char一个字节,int四个字节,

struct C
{
    char a;//1+1
    short b;//2
    int c;//4
};//8

struct D
{
    char a;//1+3
    int b;//4
    short c;//2
};//10+2

struct E
{
    char a;//1+3
    float b;//4
    int c;//4+4
    double d;//8
};

struct F
{
    int a;//4
    char b;//1
};//5+3

struct G
{
    char a;
    int b;
};

struct H
{
    char a;//1+3
    int b;//4
    double c;//8
    int *d;//4
};//20+4

struct II
{
    int a;
    char b;
};

struct I
{
    float x;//4
    //struct II y;//8
    double y;
};//12  单个最大类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值