方式1
struct stu{
char const *name; //姓名
int num; //学号
char sex; //性别
float score; //成绩
};
int main(){
struct stu s1={"www",1,'m',100.0};
stu s2={"ccc",2,'m',78.0}; // 不带struct也不会报错
return 0;
}
方式2
struct stu{
char const *name;
int num;
char sex;
float score;
}s1,s2; // 定义的同时马上声明,非一次性
int main(){
s1={"www",1,'m',100.0};
s2={"ccc",2,'f',99.4};
stu s3={"xxx",3,'f',92.4};
return 0;
}
或者
struct{
char const *name;
int num;
char sex;
float score;
}s1,s2; // 定义的同时马上声明,一次性
int main(){
s1={"www",1,'m',100.0};
s2={"ccc",2,'f',99.4};
return 0;
}
方式3
typedef struct{
char const *name;
int num;
char sex;
float score;
} STU; // 给结构体起别名
int main(){
STU s1={"www",1,'m',100.0};
return 0;
}