数据类型是计算机分配内存的依据。
结构体:
struct stu
{
char name[20];
int age;
char id[20];
};
{
char name[20];
int age;
char id[20];
};
struct stu stu1;
---------------
struct stu
{
char name[20];
int age;
char id[20];
}stu1;
--------------
struct //只有一个时用,例如老板
{
char name[20];
int age;
char id[20];
}boss;
--------------------
---------------
struct stu
{
char name[20];
int age;
char id[20];
}stu1;
--------------
struct //只有一个时用,例如老板
{
char name[20];
int age;
char id[20];
}boss;
--------------------
typedef struct stu //用typedef给结构体数据类型起别名
{
char name[20];
int age;
char id[20];
}STU;
{
char name[20];
int age;
char id[20];
}STU;
STU stu1;
-----------------------
结构体初始化赋值:
STU stu1 = {"larry",20,"123456456"};
-----------------------
结构体初始化赋值:
STU stu1 = {"larry",20,"123456456"};
STU stu2;
stu2.name = "larry";
stu2.age = 18;
stu2.id = "123456789";
stu2.name[0] = 'h';
stu2.name = "larry";
stu2.age = 18;
stu2.id = "123456789";
stu2.name[0] = 'h';
STU stu[3] = {{"aa",10,"11"},{"bb",20,"22"},{"cc",30,"33"}};
================================================
联合体:
联合体:
union data
{
int a;
char b;
double c;
};
data da1;
da1.a = 10;
data da2;
da2.b='b';
==================================================
枚举类型:
enum MyEnum
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday
};
MyEnum day;
day = Monday;//day值为0
---------------------------
enum MyEnum
{
Monday=1,
Tuesday=2,
Wednesday=3,
Thursday=4,
Friday=5
};
MyEnum day;
day = Monday;//day值为1
{
int a;
char b;
double c;
};
data da1;
da1.a = 10;
data da2;
da2.b='b';
==================================================
枚举类型:
enum MyEnum
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday
};
MyEnum day;
day = Monday;//day值为0
---------------------------
enum MyEnum
{
Monday=1,
Tuesday=2,
Wednesday=3,
Thursday=4,
Friday=5
};
MyEnum day;
day = Monday;//day值为1