预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共33页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

C语言程序设计结构体类型(struct)结构体类型的声明结构体变量的定义结构体变量的初始化结构体成员的引用structdate1 { intx; structdate2 { inti; charc1; }one; charc2; }two={1,1,'A','B'}; main() { two.one.c1+=32; printf("%d\n",++two.x); printf("%d\n",two.one.i); printf("%d\n",sizeof(two)); printf("%d\n",sizeof(two.one)); }structdate2 { inti; charc; }two,four; main() { two.i=1; two.c='A'; four=two; printf("%d,%c\n",four.i,four.c); }结构体数组结构体数组的定义结构体数组的初始化例:以下程序输出结果是?结构体和指针structst { intn; charch; }; main() { structsta={10,'A'},*p=&a; printf("%d,%c\n",a.n,a.ch); printf("%d,%c\n",(*p).n,(*p).ch); printf("%d,%c\n",p->n,p->ch); }2、指针变量作为结构体成员3、指向结构数组的指针4、结构指针作为函数参数共用体类型(union)共用体类型的声明共用体变量的定义共用体变量的初始化unionu_type { charc; inti; }; voidmain() { unionu_typeu1,u2,*p=&u1; u1.c='a';u1.i=0x3f41; printf("%c,%x\n",(*p).c,p->i); u2=u1; u2.i=0x3f42; printf("%c,%x\n",u2.c,u2.i); }结构体与共用体的区别例:以下程序输出结果是?例:以下程序输出结果是?枚举类型(enum)枚举类型的声明枚举变量的定义和使用main() { enumcards{club,diamond=2,heart,spade}card1=club; inta[5]={10,20,30,40}; printf("%d",a[card1]+a[spade]); } A)50B)20C)10D)30用typedef定义类型别名1.typedef用于定义数组类型别名 typedefintARRAY[10]; /*说明ARRAY为有10个元素的整型数组类型别名*/ ARRAYa,b; /*等价于inta[10],b[10];*/ 2.typedef用于定义结构体类型别名 typedefstruct { charnumber[10]; charname[10]; floatscore[5]; }STUDENT;/*说明STUDENT为一个结构体类型别名*/ STUDENTstu; /*定义stu为上述结构体类型的变量。*/3.typedef用于定义共用体类型别名 typedefunion { inti; charCh; }UTYPE;/*说明UTYPE为一个共用体类型别名。*/ UTYPEx,y;/*定义x与y为上述共用体类型的变量*/ 4.typedef用于定义枚举类型别名 typedefenum{male,female}ETYPE; /*说明ETYPE为一个枚举类型别名*/ ETYPEsex; /*定义sex为上述枚举类型的变量*/ 5.typedef用于定义指针类型别名 typedefint*POINTER; /*说明POINTER为一个指针类型别名*/ POINTERp1; /*等价于int*p1*/例:若有以下类型说明,则()是正确的叙述。