##C语言结构体
结构体是可以自定义的一种数据类型,允许存储不同的数据类型的项目
例如,一个人具有属性或者特征为:姓名、身高、体重、年龄、性别等等
定义结构体:
struct name{
member 1;
member 2;
… … …
};
关键字为struct ,里面的成员至少需要两个
示例:
#include <stdio.h>
struct STU{
char *name; //姓名
int age; //年龄
char sex; //性别
float score; //成绩
};
int main(){
struct STU stu1;
stu1.name = "fang";
stu1.age = 18;
stu1.sex = 'M'; //用M表示男性,W表示女性
stu1.score = 99;
printf("Hello everyone! My name is %s,%d years old , a naughty boy, but with good scores(%.2f) !", stu1.name, stu.age,stu1.score, s);
return 0;
}