#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;
}
求结构体所占字节大小
最新推荐文章于 2024-07-25 11:35:59 发布