结构体写法(Struct)

发布时间 2023-12-19 14:31:44作者: SweetTea_lllpc

一、

struct stu{
    char *name;   //姓名
    int num;      //学号
    int age;      //年龄
    char group;   //所在小组
    float score;  //成绩
} stu1;     //定义结构体类型的同时定义结构体变量
/*
 *其他写法:
 * ①                                            //先定义结构体类型,再定义结构体变量。
 * struct stu{
    char *name;   //姓名
    int num;      //学号
    int age;      //年龄
    char group;   //所在小组
    float score;  //成绩
   };
   struct stu stu1, stu2;

   ②
   struct {
    char *name;   //姓名
    int num;      //学号
    int age;      //年龄
    char group;   //所在小组
    float score;  //成绩
   }stu1, stu2;

   ③                                           
   typedef struct student{
    char *name;   //姓名
    int num;      //学号
    int age;      //年龄
    char group;   //所在小组
    float score;  //成绩       
   }stu;
   stu stu1;

   ④                                            //常用
   typedef struct{
    char *name;   //姓名
    int num;      //学号
    int age;      //年龄
    char group;   //所在小组
    float score;  //成绩       
   }stu;
   stu stu1;
   
 */