08.C语言之结构、联合、枚举

结构体定义

struct Date{
    int year;
    int month;
    int day;
};
struct Date{
    int year,month,day;
}


结构体别名

typedef struct Date Date;
typedef struct Student Student;
typedef struct Date{
    int year;
    int month;
    int day;
}Date;


结构体变量

struct Date{
    int y,m,d;
}struct Date day;
struct Date{
    int y,m,d;
}day;

struct Date day1,day2...;

前两种可以继续定义变量

struct{
    int y,m,d;
}day;  //变量必须同时指出


变量用.      x.y = 1992; x.m = 4;

指针用->   p->y = 1992; p->m = 4;

*p = x;  (*p).y = 1993;

扫描二维码关注公众号,回复: 2066545 查看本文章


*(a+2).y = 

(a+2)->y = 

a[2].y = 

等价


结构团体变量占据的内存空间至少是所有成员占据内存的总和
共用体变量存储空间是占用最大存储空间成员所需存储空间
版权声明:本文为博主原创文章,未经博主允许不得转载。

猜你喜欢

转载自blog.csdn.net/wonz5130/article/details/80992503