结构体
来源:互联网 发布:观人于微而知其著 编辑:程序博客网 时间:2024/05/18 12:35
联合 与 结构体的区别:
同一时刻,结构体的所有成员都成在,联合体只有一个被选中的成员
同一时刻,结构体的所有成员都成在,联合体只有一个被选中的成员
结构体不同成员可以有不同的值,联合体对成员赋值,其他成员的值将被重写。
结构体的定义
struct Date{
int year;
int month;
int day;
};
struct Date now;
now.year = 1;
now.month = 1;
now.day = 1;
printf("%d%d%d", now.year, now.month, now.day);
struct Date
{
int year;
int month;
int day;
} now, now2;
#define STU struct Date
STU{
int year;
int month;
int day;
};
STU now, now2;
struct Date
{
int year;
int month;
int day;
} now, now2;
struct
{
int year;
int month;
int day;
} now, now2;
枚举
enum weekday{
monday,
tuesday,
wednesday,
} test;
test = monday;
printf("%d", test);
联合
union scope{
int num;
char str;
} ss;
0 0