正在加载图片...
11.6结构体和指针 mainO i struct student long int num char name 20 char sex 地址 例 intloat.score, struct student stul;量名成员 stu H &n struct student *p=&sturt, p=&ks n=10 stul, num=101;(*p)um=101 strcpy(stu 1. name, Li Lin") p->sex=M p->score=89.5 printf("nNo: %ld nname: %snsex: %c Inscore: %f\n (p). num, p->name, stu 1. sex, p->score)11.6 结构体和指针 «指向结构体变量的指针 v定义形式:struct 结构体名 *结构体指针名; 例 struct student *p; v使用结构体指针变存量放引结用构成体员变形量式在内存的起始地址 num name sex age stu p struct student { int num; char name[20]; char sex; int age; }stu; struct student *p=&stu; (*结构体指针名).成员名 结构体指针名->成员名 结构体变量名.成员名 指向运算符 优先级: 1 结合方向:从左向右 例 指向结构体的指针变量 main() { struct student { long int num; char name[20]; char sex; float score; }stu_1, *p; p=&stu_1; stu_1.num=89101; strcpy(stu_1.name, "Li Lin"); p->sex='M'; p->score=89.5; printf("\nNo:%ld\nname:%s\nsex:%c\nscore:%f\n" , (*p).num,p->name,stu_1.sex,p->score); } 例 int n; int *p=&n; *p=10;  n=10 struct student stu1; struct student *p=&stu1; stu1.num=101;  (*p).num=101
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有