求结构体所占字节大小

#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct text1                  \\结构体text1重命名为t1
{
    int a;
    char b;
    int  arr[15];
}t1;
typedef struct                 \\重新定义结构体类型,结构体类型为dsa
{
    int ab;
    char bb;
    char abb[46];
}dsa;
typedef struct                 \\重定义结构体类型,结构体类型为dww
{
    int ab;
    dsa asw;                        \\定义结构体类型为dsa的变量asw
    char abb[46];
}dww;
int main(int argc, const char *argv[])
{
    struct text1 t1={10,'e',21};
    printf("%d %c %d\n",t1.a,t1.b,t1.arr[1]);
    dsa *p=(dsa *)malloc(sizeof(dsa) );\\堆区申请结构体变量
    p->ab=21;
    p->bb='d';
    strcpy(p->abb,"zjdkas");//指针指向的数组输入
    printf("%d %c %s",p->ab,p->bb,p->abb);//堆区申请的结构体变量,打印输出
    printf("%ld\n",sizeof(dsa));\\结构体dsa所占字节 52
    printf("%ld\n",sizeof(t1));结构体ti所占字节  68
    printf("%ld\n",sizeof(dww));\\结构体dww所占字节 104
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值