正在加载图片...
C语言程序设计上机指导与同步训练 char name [101 float scor student1 scanf( &student num, studentI name &student. age &student1 score); student age++i 3.结构体数组 (1)先定义结构体类型。 (2)然后定义结构体类型数组,方法同普通类型数组的定义。 char name [101 int age float score tudent [5] student [o]. score =480 4.指向结构体变量或数组的指针 (1)通过指向结构体变量或数组的指针,访问结构体变量或数组的成员的格式。 p)成员名 →成员名 等价于结构体变量.成员名 称为指向运算符;与成员运算符()一样,级别最高 [ int num struct strdent* p (*p).num=1001; strcpy (p-> name "Wanglin")i (*p).age=20; 基础训练(A) 填空题 1.定义结构体的关键字是·256· C 语言程序设计上机指导与同步训练 ·256· 如: struct strdent { int num ; char name [10] ; int age ; float score; } student1 ; scanf( “%d %s%d%f” , &student1.num,student1.name , &student1.age ,&student1.score) ; student1.age++ ; 3. 结构体数组 (1) 先定义结构体类型。 (2) 然后定义结构体类型数组,方法同普通类型数组的定义。 struct strdent { int num ; char name [10] ; int age ; float score; } student [5] ; student[0].score = 480; 4. 指向结构体变量或数组的指针 (1) 通过指向结构体变量或数组的指针,访问结构体变量或数组的成员的格式。 ( * p ) . 成员名 ; p 成员名; 等价于 结构体变量. 成员名; -------称为指向运算符;与成员运算符(.) 一样,级别最高; 如: struct strdent { int num ; char name [10] ; int age ; float score; } student1 ; struct strdent* p ; p = &student1 ; (*p).num=1001; strcpy(p-> name , “Wanglin”); (*p).age=20; p -> score=480 ; 基础训练(A) 一、填空题 1. 定义结构体的关键字是____________。
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有