结构体类型的创建
#include "stdafx.h"
#if 0
一、有名结构体的俩种定义方式:
(1)定义类型的同时,完成了变量的定义
//struct Student 相当于创建了类型,相当于int
struct Student
{
char name[100];
char sex;
int age;
float score;
}stu; //既然 struct Student为类型则 stu为变量
(2)先有类型,再声明/定义变量
struct Student
{
char name[100];
char sex;
int age;
float score;
}
struct Student s;
//优点:一次定义,多处使用,会带来新的命名(提高复杂度)
二、无名结构体
(1)定义类型的同时,完成了变量的定义
struct
{
char name[100];
char sex;
int age;
float score;
}stu;
//优点:无名结构体不引入新的类型(降低复杂度)
三、别名结构体
(1)定义结构体类型的别名
typedef struct Student //加上student方便以后追溯但可以省略
{
char name[100];
char sex;
int age;
float score;
}STU; //此时的STU为结构体类型的别名,而不为变量
#endif
int _tmain(int argc, _TCHAR* argv[])
{
//printf("%s\n", s.name);
//printf("%s\n", s.sex);
return 0;
}