第九章测试1.
#include<stdio.h>
#include<string.h>
struct A
{int a;
char b[10];
double c;};
void f(struct A t);
main()
{struct A a={1001,"ZhangDa",1098.0};
f(a);
printf("%d,%s,%6.1f",a.a,a.b,a.c);
}
void f(struct A t)
{t.a=1002;
strcpy(t.b,"ChangRong");
t.c=1202.0;
}
结果是
A:1002,Zhang Da,1202.0 B:1001,zhangDa,1098.0 C:1002,chang Rong,1202.0 D:1001,changRong,1098.0
答案:B
2.
#include <stdio.h>
struct ord
{ int x,y;} dt[2]={1,2,3,4};
main( )
{ struct ord *p=dt;
printf(“%d,”,++p->x);
printf(“%d”,++p->y);
}
程序的运行结果是
A:3,4 B:2,3 C:
4,1
D:1,2 3.#include <stdio.h>
struct st
{ int x, y;} data[2]={l,10,2,20};
main()
{ struct st *p=data;
printf("%d,", p->y);
printf("%d",(++p)->x);
}
程序的运行结果是
A:20,1 B:10,2 C:10,1 D:20,2 4.
#include <stdio.h>
main()
{ struct STU
{ char name[9];
char sex;
double score[2];
};
struct STU a={"Zhao",'m',85.0,90.0),b={"Qian",'f',95.0,92.0);
b=a;
printf("%s,%c,%2.0f,%2.0f", b.name,b.sex,b.score[0],b.score[1]);
}
程序的运行结果是
A:
Zhao,m,85,90
B:Qian,f,95,92
C:Zhao,f,95,92
D:Qian,m,85,90 5.有以下程序
struct S
{ int a,b;} data[2]={10,100,20,200};
main()
{ struct S p=data[1];
printf("%d",++(p.a));
}
程序运行后的输出结果是
A:21 B:20 C:10 D:11 6.
#include <stdio.h>
typedef struct
{int num;double s;} REC;
void fun1(REC x)
{x.num=23;x.s=88.5;}
main()
{ REC a={16,90.0};
fun1(a);
printf("%d ",a.num); }
上述程序的输出结果为 ________
A:16 B:90 C:23 7.
下程序运行结果________
#include <stdio.h>
#include <string.h>
struct A
{int a;
char b[10];
double c;
};
void f (struct A *t);
main()
{struct A a={1001,”ZhangDa”,1098.0};
f(&a);
printf(“%d,%s,%6.1f ”,a.a,a.b,a.c);
}
void f(struct A *t)
{
strcpy(t->b, ”ChangRong”);
}
A:1001,"ChangRong",1098.0 B:1001,ChangRong,1098.0 C:1001,ZhangDa,1098.0 D:1001,”ZhangDa”,1098.0 8.
以下程序运行后的输出结果是 ________
struct NODE
{ int num;
struct NODE *next; }
main()
{ struct NODE s[3], *p, *q, *r;
int sum=0;
s[0].num=1; s[1].num=2; s[2].num=3;
s[0].next=s+1; s[1].next=s+2; s[2].next=s;
p=s; q=p->next; r=q->next;
sum+=q->next->num;
sum+=r->next->next->num;
printf("%d ", sum);
}
A:1 B:4 C:2 D:5 9.
函数fun的功能是统计person所指结构体数组中所有性别(sex)为M的记录的个数存入n中,请填空:
#define N 3
typedef struct
{int num;
char nam[10];
char sex;} SS;
int fun(SS person[])
{int i,n=0;
for(i=0;i<N;i++) if(______==’M’ ) n++;
return n;
}
main()
{SS W[N]={{1,”AA”,’F’},{2,”BB”,’M’}, {3,”CC”,’M’}};
int n;
n=fun(W);
printf(“n=%d ”,n); }
A:person[i].sex B:person[i] C:person[i].name 10.
以下程序运行后的输出结果是________
#include <stdio.h>
main()
{ char *p; int i;
p=(char *)malloc(sizeof(char)*20);
strcpy(p,"welcome");
for(i=6;i>=0;i--) putchar(*(p+i));
printf(" -"); free(p);
}
A:emoclew B:emocle C:welcome D:elcome