{ scanf(\【2】 ); } outone (int *b)
{ printf(\【3】 ); } main() { int *p;
getone(&p); assone(p); outone(p); }
18.下列程序的输出结果是 【1】 。
#define MAX(a,b) a>b #define EQU(a,b) a==b #define MIN(a,b) a
main() { int a=5,b=6; if(MAX(a,b)) printf(\); if(EQU(a,b)) printf(“EQU\\n”); if(MIN(a,b)) printf(\
11.2 例题分析与解答
1.以下程序的输出结果是( )。
struct HAR {
int x,y;
struct HAR *p; }h[2]; main() {
h[0].x=1; h[0].y=2; h[1].x=3;
h[1].y=4;
h[0].p=&h[1];h[1].p=h;
printf(\ }
2.以下程序的输出结果是( )。
union myun {
struct {
int x,y,z; }u; int k; }a; main() { a.u.x=4; a.u.y=5; a.u.z=6; a.k=0;
printf(%d\\n\ }
5.下面程序的输出结果为( )。
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] }; main()
{ p=aa;
printf(\ printf(\ printf(\*p->y)); }
11.3 测试题
11.3.1 选择题
3.若有以下说明和语句,则值为6的表达式是( )。
struct st
{ int n;
struct st *next; };
struct st a[3],*p;
a[0].n=5; a[0].next=&a[1]; a[1].n=7; a[1].next=&a[2]; a[2].n=9; a[2].next=\\'\\\\0\\';
p=&a[0];
4.已知字符0的ASCII代码值的十进制数为48,且数组的第0个元素在低位,以下程序的输出结果是( )。
main()
{ union { int i[2]; long k; char c[4]; } r,*s=&r;
s->i[0]=0x39; s->i[1]=0x38; printf(\}
5.以下程序的输出结果是( )。
typedef union { long x[2]; int y[4]; char z[8]; } MYTYPE; MYTYPE them; main()
{ printf(\
6.以下程序的输出结果是( )。
struct st
{ int x; int *y; } *p;
int dt[4]={10,20,30,40};
struct st aa[4]={50,&dt[0],60,&dt[0],60,&dt[0],60,&dt[0],}; main() { p=aa;
printf(\ printf(\ printf(\*p->y)); }
7.以下程序的输出结果是( )。
typedef union { long i; int k[5]; char c; } DATE; struct date { int cat; DATE cow; double dog; } too; DATE max;
main()
{ printf(\
11.3.2 填空题
1.以下MIN 函数的功能是:在查找带有头结点的单向链表中,结点数据域的最小值作为函数值返回,请填空。
struct node { int data; struct node *next;
};
int MIN(struct node *first) { struct node *p; int m;
p=first->next; m=p->data;
for(p=p->next; p!='\\0'; p= 【1】 ) if( 【2】 ) m=p->data;
return m; }
2.函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾,单向链表的头指针作为函数值返回。请填空。
#include \struct list
{ char data;
struct list *next;
} ;
struct list *creat() { struct list *h,*p,*q;
char ch ;
h=_____malloc(sizeof( 【1】 )); p=q=h;
ch=getchar();
while(ch!='?')
{ p= 【2】 malloc(sizeof( 【3】 )); p->data=ch; q->next=p; q=p;
ch=getchar(); }
p->next='\\0'; 【4】 ;
3.以下程序建立了一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为–1时,表示输入结束(链表头结点的 data 域不放数据,表空的条件是ph->next==NULL)。请填空。
#include
{ int data;
struct list *next;}; 【1】 creatlist()
{ struct list *p,*q,*ph;
int a;
ph=(struct list *)malloc(sizeof(struct list));
p=q=ph;
printf(\ scanf(\ while(a!=-1)
{ p=(struct list *)malloc(sizeof(struct list)); p->data=a; q->next=p; 【2】 =p; scanf(\ }
p->next='\\0'; return(ph); }
main()
{
struct list *head; head=creatlist(); }
}
4.字符'0'的ASCII码的十进制数为48,且数组的第0个元素在低位,则以下程序的输出结果是 【1】 。
#include
printf(\ }
12.2 例题分析与解答
2.以下程序用来统计文件中字符个数,请填空。
#include\ main()
{ FILE *fp;
long num=0L;
if((fp=fopen(\ { pirntf(\ exit(0); }
while(______) { fgetc(fp); num++;
}
printf(\ fclose(fp); }
3.下面的程序执行后,文件test.txt中的内容是( )。
#include\
void fun(char *fname,char *st) { FILE *myf;
int i;
myf=fopen(fname,\ for(i=0;i main() { fun(\ fun(\ } 4.以下程序段打开文件后,先利用 fseek 函数将文件位置指针定位在文件末尾,然后调用ftell函数返回当前文件位置指针的具体位置,从而确定文件长度,请填空。 FILE *myf; long f1; myf=______(\