//结构体定义及赋初始值的三种方法
// 方法一
struct Student
{
char * name;
int age;
float score;
}s1={"s1",23,97.0f};
// 方法二
typedef struct Person
{
char * name;
int age;
float score;
}person;
// 方法三
struct
{
char * name;
int age;
float score;
}a={"a",23,97.0f};
int main()
{
//
struct Student s = {"student",23,97.0f};
printf("%s\n%d\n%f\n",s.name,s.age,s.score);
//
person p = {"person",23,97.0f};
printf("%s\n%d\n%f\n",p.name,p.age,p.score);
//
printf("%s\n%d\n%f\n",a.name,a.age,a.score);
return 0;
}
转载于:https://blog.51cto.com/skyarac/1608119