struct 结构体名{
结构体所包含的变量或数组;
};
struct stu{
char *name; //姓名
int num; //学号
int age; //年龄
char group; //所在学习小组
float score; //成绩
};
int main(){
struct stu s1;
s1.name="张三";
s1.num=2001;
s1.age=18;
//...
printf("%s\n",s1.name);
printf("%d\n",s1.num);
return 0;
}
或者写成结构体数组
struct {
char* name;
int xh;
int age;
char* gender;
}Stu = { "张三",2001,18,"男" };
int main() {
printf("%s同学的学号是%d,是%d岁一名%s同学。\n", Stu.name, Stu.xh, Stu.age, Stu.gender);
return 0;
}
//这里的字符串要用到解引用操作符,对他的内存解析才能正常输出要不然就会出现以下错误
会引起好多bug,我就遇到了(难受)
标签:struct,int,s1,name,char,Stu,类型,结构 From: https://blog.51cto.com/u_15812262/5780472