当前位置:文档之家› C程第十一章结构体上机习题

C程第十一章结构体上机习题

第十一章结构体与共用体
问题与思考
1.下面程序的运行结果是___________.
main()
{
struct cmplx{int x;
int y;
}cnum[2]={1,3,2,7};
printf("%d\n",cnum[0].y/cnum[0].x*cnum[1].x);
}
:
a)0 b)1 c)3 d)6
2.以下对结构体变量stu1中成员age的非法引用是____b____.
struct student
{int age;
int num;
}stu1,*p;
p=&stu1;
a) b)
c)p->age d)(*p).age
/
3.以下scanf函数调用语句中对结构体变量成员的不正确引用是_____d___.
struct pupil
{char name[20];
int age;
int sex;
}pup[5],*p;
p=pup;
a)scanf("%s",pup[0].name);
b)scanf("%d",&pup[0].age);
\
c)scanf("%d",&(p->sex));
d)scanf("%d",p->age);
4.以下程序的运行结果是___10,x_____.
struct n{
int x;
char c;
};
main()
{struct n a={10,'x'};
|
func(a);
printf("%d,%c",,;
}
func(struct n b)
{
=20;
='y';
}
5.若有定义:

struct num
{int a;
int b;
float f;
}n={1,3,};
struct num *pn=&n;
则表达式pn->b/*++pn->b的值是___12_____,表达式(*pn).a+pn->f的值是.
6.以下程序的运行结果是____7,3____.
struct ks
·
{int a;
int *b;
}s[4],*p;
main()
{
int n=1;
printf("\n");
for(i=0;i<4;i++)
{
s[i].a=n;
·
s[i].b=&s[i].a;
n=n+2;
}
p=&s[0];
p++;
printf("%d,%d\n",(++p)->a,(p++)->a);
}
7.结构数组中存有三人的姓名和年龄,以下程序输出三人中最年长者的姓名
和年龄。

请在_______内填入正确内容。

&
stati struct man{
char name[20];
int age;
}person[]={"li=ming",18,
"wang-hua",19,
"zhang-ping",20
};
main()
{struct man *p,*q;

int old=0
p=person;
for( ;p_____;p++)
if(old<p->age)
{q=p;______;}
printf("%s %d",______);
}
8.以下程序段的功能是统计链表中结点的个数,其中first为指向第一个结点的指针(链表不带头结点)。

请在______内填入正确内容。

~
struct link
{char data ;
struct link *next;
};
....
struct link *p,*first;
int c=0;
p=first;
while(_____)
#
{_______;
p=_______;
}
9.有以下程序输出结果是。

#include<>
struct stu
{int num;
char name[10];
int age;
<
};
void fun(struct stu *p)
{printf("%s\n",(*p).name);}
main()
{struct stu students[3]=
{{9801,"zhang",20},{9802,"Wang",19},{9803,"zhao",18}};
fun(students+2);}
10.根据下面的定义,能打出字母M的语句是 c 。

struct person
{ char name[9];
int age;
}
struct person class[10]={ 〞John〞,17, 〞Paul〞,19, 〞Mary〞,18,
〞Adam〞,16};
(〞%c\n〞,class[3].name);
(〞%c\n〞,class[3].name[1]);
(〞%c\n〞,class[2].name[1]);
(〞%c\n〞,class[2].name[0];。

相关主题