在数据类型中,结构体是C语言中相对复杂的一种,把它和指针这种技术联系起来使用,无疑很有学习意义
#include <stdio.h>
struct Student {
//年龄
char *name;
//编号
char *id;
//年龄
unsigned age;
};
int main(){
struct Student students[] = {
{"小明","15061",11},
{"小红","15062",11},
{"小童","15063",10}
};
//定义结构体指针
struct Student *studentp = &students[0];
//第一种方法
(*studentp).name = "指针小明";
//第二种方法
studentp->id = "指针15062";
for (int i = 0; i<sizeof(students)/sizeof(struct Student); i++) {
printf("%s\t%s\t%d\n",students[i].name,students[i].id,students[i].age);
}
return 0;
}