文档介绍:1结构体指针 struct student { int num; char name[20]; char sex; int age; }; struct student stu; / *定义结构体变量*/ struct student *pstu; /*定义结构体指针*/ pstu = &stu; ?怎样通过 stu 访问 stu 的成员? ? = 1; /*成员运算符*/ ?= “mary ”; ?怎样通过 pstu 访问 stu 的成员? ?(*pstu).num = 1; ?pstu->name = “mary “;/*指向运算符*/ ?第二种更常用 pstu stu num name sex age 2练****题 struct student { int num; char name[20]; char sex; struct date birthday; }; 请定义一个指针变量,指向此结构体,利用指针变量, 存储 1位学生的信息,并输出这位学生的信息。 3 ?#include "" ? struct student ?{ int num; ? char name[20]; ? char sex; ? struct date birthday; ?}; 4 ? void main() ?{ ? struct student stu, * pstu; ? int i; ? pstu=&stu; ? printf("input num:"); scanf("%d",&pstu->num); ? printf("\ninput name:"); scanf("%s",pstu->name); ? getchar(); printf("\ninput sex:"); scanf("%c",&pstu->sex); ?? printf("\ninput year:"); scanf("%d",&pstu->); ? printf("\ninput month:"); scanf("%d",&pstu->); ? printf("\ninput day:"); scanf("%d",&pstu->); ? 5 ?? printf("No:%d\n",pstu->num); ? printf("Name:%s\n",pstu->name); ? printf("Sex:%c\n",pstu->sex); ? printf("Year:%d\n",pstu->); ? printf("Month:%d\n",pstu->); ? printf("Day:%d\n",pstu->); ??} 6结构体数组的指针? struct STUDENT stu[4]; ? struct STUDENT * pt; ? pt = stu; ?如何引用 stu[i] ? ?使用 pt++ ,使 pt 指向 stu[i] ? pt-> studentID ?等价于 stu[i]. studentID …2…3…4… 1 stu[0] stu[1] stu[2] pt Pt++ stu[3] 7练****题 struct student { int num; char name[20]; char sex; struct date birthday; }; ? struct student stu[N]; 利用结构体数组指针变量,存储 N个学生的信息,并输出这 N个学生的信息。 8 ?#define N 2 ? struct date{ ? int year; ? int month; ? int day; ?}; ? struct student ?{ int num; ? char name[20]; ? char sex; ? struct date birthday; ?}; 9 ? void main() ?{ ? struct student stu[N], * pstu; ?