结构体

概念

结构体是一种可以由我们自行定义的数据类型


struct student
{
	int num;
	int score;
	float avg;
}

struct student Tom;
//结构体变量

struct student Class[50];
//结构体数组

结构体定义

结构体关键字:struct (翻译:结构体)

结构体内包含 不同的 数据类型


struct 结构体名
{
	成员列表
}

访问成员规则

类似js的对象,但完全不一样

结构体普通变量通过 "." 来访问成员,例如:Tom.num

结构体指针变量通过 "->" 来访问成员,例如:p->id

posted @ 2022-06-07 17:20  独舟者  阅读(72)  评论(0)    收藏  举报