2016C语言习题全集及答案:结构体和共用体02.docVIP

  • 102
  • 0
  • 约1.83千字
  • 约 3页
  • 2017-07-05 发布于江西
  • 举报

2016C语言习题全集及答案:结构体和共用体02.doc

2016C语言习题全集及答案:结构体和共用体02

第八单元 结构体和共用体 读程序题,写出程序运行的结果。 1、 #include stdio.h struct abc { int a, b, c; }; main() { struct abc s[2]={{1,2,3},{4,5,6}}; int t; t=s[0].a+s[1].b; printf(%d \n,t); } 2、 #include stdio.h struct stu { int num;char name[10]; int age;}; void fun(struct stu *p) { printf(%s\n ,(*p).name); } void main() { struct stu students[3]={{9801,Zhang,20} ,{9802,Wang, 19} , {9803,Zhao,18} }; fun(students+2); } 3、 #include stdio.h void main() { enum team { my ,your=4 ,his ,her=his+10}; printf(%d%d%d%d\n,my,your,his,her); } 4、 #include stdio.h struct st { int x;int *y;} *p ; int dt[4]={10,20,30,40}; struct st aa[4]={50,dt[0],60,dt[1],70,dt[2],80,dt[3] }; void main() { p=aa; printf(%d, , ++p-x); printf(%d, ,(++p)-x); printf(%d\n,++(*p-y)); } 5、 #include stdio.h union myun { struct { int x, y, z; } u; int k; } a; void main() { a.u.x=4; a.u.y=5; a.u.z=6; a.k=0; printf(%d\n,a.u.x); } 6、 #include stdio.h struct STU { char num[10]; float score[3]; }; void main() { struct STU s[3]={{“20021”,90,95,85},{“20022”,95,80,75}, {“20023”,100,95,90}},*p=s; int i; float sum=0; for(i=0;i3;i++) sum=sum+p-score[i]; printf(“%6.2f\n”,sum); } 7、 #include stdio.h #include stdlib.h struct NODE { int num; struct NODE *next; }; void main() { struct NODE *p,*q,*r; p=(struct NODE*)malloc(sizeof(struct NODE)); q=(struct NODE*)malloc(sizeof(struct NODE)); r=(struct NODE*)malloc(sizeof(struct NODE)); p-num=10; q-num=20; r-num=30; p-next=q;q-next=r; printf(“%d\n”,p-num+q-next-num); } 8、 #include stdio.h typedef union student { char name[10]; long sno; char sex; float score[4]; } STU; void main() { STU a[5]; printf(“%d\n”,sizeof(a)); } 2

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档