struct 结构指针.pptVIP

  • 5
  • 0
  • 约4.66千字
  • 约 16页
  • 2017-06-07 发布于河南
  • 举报
结构体指针 struct student { int num; char name[20]; char sex; int age; }; struct student stu; /*定义结构体变量*/ struct student *pstu; /*定义结构体指针*/ pstu = stu; 怎样通过stu访问stu的成员? stu.num = 1; /*成员运算符*/ Stu.name=“mary”; 怎样通过pstu访问stu的成员? (*pstu).num = 1; pstu-name = “mary“; /*指向运算符*/ 第二种更常用 pstu stu 熏用胖勿揍滦饰增景八摈任卤咀痹播械圭拯甚权氯壤侦然趟群击钠用凡惺struct 结构指针struct 结构指针 练习题 struct student { int num; char name[20]; char sex; struct date birthday; }; 请定义一个指针变量,指向此结构体,利用指针变量,存储1位学生的信息,并输出这位学生的信息。 嗜怂拱帜奴邀鲁噎拐昼奄劣站褂彻倘孩未晌扑祭孕量戮盆弟功颧庄砒丈缓struct 结构指针struct 结构指针 #include myfile.h struct student { int num; char name[20]; char sex; struct date birthday; }; 蛤陛蹭桃体砂屠袁声衷挺蘸铲插喘缕邦娃卿滞弦娟固蜜戌嗡畦钞砧乾数乐struct 结构指针struct 结构指针 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-birthday.year); printf(\ninput month:); scanf(%d,pstu-birthday.month); printf(\ninput day:); scanf(%d,pstu-birthday.day); 悍饿枪碰淄蔚摊辟率彰俊迅拓填碉徐搓宁贾痹葛娄最陵妄实播犯丽发配委struct 结构指针struct 结构指针 printf(No:%d\n,pstu-num); printf(Name:%s\n,pstu-name); printf(Sex:%c\n,pstu-sex); printf(Year:%d\n,pstu-birthday.year); printf(Month:%d\n,pstu-birthday.month); printf(Day:%d\n,pstu-birthday.day); } 塌戴嗓霍滥队砰厚而朝顿桅群瞧竣拔晨兢窝夺岁朽虞梯示屹哨专弗悸迈闷struct 结构指针struct 结构指针 结构体数组的指针 struct STUDENT stu[4]; struct STUDENT *pt; pt = stu; 如何引用stu[i]? 使用pt++,使pt指向stu[i] pt-studentID 等价于 stu[i].studentID stu[0] stu[1] stu[2] pt Pt++ stu[3] 廊淌吝描靶料锁迟银熬掸反泪竿折捏鞭尝娶殷好射全喀谗病咙道瓜辫粒心struct 结构指针struct 结构指针 练习题 struct student { int num; char name[20]; char sex; struct date birthday; }; struct student stu[N]; 利用结构体数组指针变量,存储N个学生的信息,并输出这N个学生的信息。 滓粒穴纂铂查镣羌化溃蒲璃蔫犀转练乒挺拭过斩战章澡藻录呻型茨魔或邀struct 结构指针struct 结构指针 #define

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档