C++定义结构体类型变量的方法
1、先声明结构体类型再定义变量名,在定义了结构体变量后,系统会为之分配内存单元。
struct Student{
//自定义结构体变量
int num;//学号
char sex;//性别
int age;//年龄
};
2、在声明类型的同时定义变量
一般形式为
struct 结构体名
{ 成员表列
}变量名表列;
struct Student{
//自定义结构体变量
int num;//学号
char sex;//性别
int age;//年龄
}student1,student2;
3、直接定义结构体类型变量(开发中很少用,小林也不建议用)
一般形式为
struct
{ 成员表列
}变量名表列;
struct {
//自定义结构体变量
int num;//学号
char sex;//性别
int age;//年龄
}stude