有以下语句 struct S { int g; char h; } T; 则下面叙述中不正确的是()。
A.S 是结构体名
B. 该结构体包含 2 个成员
C. S 是 struct 类型的变量
D. T 是 struct S 类型的变量
A.S 是结构体名
B. 该结构体包含 2 个成员
C. S 是 struct 类型的变量
D. T 是 struct S 类型的变量
第1题
A.10
B.11
C.20
D.21
第2题
有以下程序
struct STU
{ char num[10]; float score[3]; };
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;i<3;i++)
sum=sum+p->score[i];
printf("%6.2f\n",sum);
}
程序运行后的输出结果是
A.260.00
B.270.00
C.280.00
D.285.00
第3题
设有以下说明语句 typedef struct { int n; char ch[8]; }PER;
A.PER 是结构体变量名
B.PER 是结构体类型名
C.typedef struct 是结构体类型
D.struct 是结构本类型名
第4题
A.s>>>=1;
B.int i=s.length();
C.String ts=s.trim();
D.String t=s+”!”;
第5题
根据下面的定义,能打印出字母M的语句是()。 struct person { char name[9]; int age; }; struct person class[10]={"John",17,"Paul",19,"Mary",18,"Adam",16};
A.printf("%c\n",class[3].name};
B.printf("%c\n",class[2].name[0]);
C.printf("%c\n",class[3].name[1]);
D.printf("%c\n",class[2].name[1]);
第6题
A.year=1985;month=4;day=4;
B.birth.year=1985;birth.month=4;birth.day=4;
C.s.year=1985;s.month=4;s.day=4;
D.s.birth.year=1985;s.birth.month=4;s.birth,day=4;
第7题
已知学生记录描述为: struct student { int no; char name[20],sex; struct { int year,month,day; } birth; }; struct student s; 设变量s中的“生日”是“1984年11月12日”,对“birth”正确赋值的程序段是()。
A.year=1984;month=11;day=12;
B.s.year=1984;s.month=11;s.day=12;
C.birth.year=1984;birth.month=11;birth.day=12;
D.s.birth.year=1984;s.birth.month=11;s.birth.day=12;
第8题
阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。
【说明】
以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。
【程序】
include <stdio.h>
include <stdlib.h>
FILE *cp;
char fname[20], buf[100];
int NUM;
struct key
{ char word[10];
int count;
}keyword[]={ "if", 0, "char", 0, "int", 0,
"else", 0, "while", 0, "return", 0};
char *getword (FILE *fp)
{ int i=0;
char c;
while((c=getc(fp))!= EOF &&(1));
if(c==EOF)
return (NULL);
else
buf[i++]=c;
while((c=fgetc(fp))!=EOF && c!="&& c!='\t' && c!='\n' )
buf[i++]=c;
buf[i]='\0';
return(buf);
}
void lookup(char *p)
{ int i;
char *q, *s;
for(i=0; i<NUM; i++)
{ q=(2);
s=p;
while(*s && (*s==*q))
{ (3))
if((4))
{ keyword[i].count++;
break;
}
}
return;
}
void main()
{ int i;
char *word;
printf("lnput file name:");
scanf("%s", fname);
if((cp=fopen(fname, "r"))==NULL)
{ printf("File open error: %s\n", fname);
exit(0);
}
NUM=sizeof(keyword)/sizeof(struct key);
while((5))
lookup(word);
fclose(cp);
for(i=0;i<NUM;i++)
printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);
}
第9题
学生的记录由学号和成绩组成,N名学生的数据己在主函数中放入结构体数组s中,请编写函数fun(),它的功能是:把分数最低的学生数据放在h所指的数组中。注意:分数低的学生可能不只一个,函数返回分数最低学生的人数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
define N 16
typedef struct
{char num[10];
int s;
}STREC;
int fun (STREC *a,STREC *b)
{
}
main ()
{
STREC s[N]={{“GA005”,82},{“GA003”,75},
{“GA002”,85},{“GA004”,78},{“GA001”,95},
{“GA007”,62},{“GA008”,60},{“GA006”,85},
{“GA015”,83},{“GA013”,94},{“GA012”,78},
{“GA014”,97},{“GA011”,60},{“GA017”,65},
{“GA018”,60},{“GA016”,74}};
STREC h[N];
int i,n;
FILE *out;
n=fun(S,h);
printf(“The %d lowest score:\n”,n);
for (i=0; i<n; i++)
printf(“%s %4d\n”,h[i].mum,h[i].s);
/*输出最低分学生的学号和成绩*/
printf(“\n”);
out=fopen("outl9.dat",“w”);
fprintf(out,“%d\n”,n);
for(i=0; i<n; i++);
fprintf(out, “%4d\n”,h[i].s);
fclose(out);
}
第10题
设有如下定义: struct ss {char name[10]; int age; char sex; }std[3],*p=std; 下面各输入语句中错误的是()。
A.scanf("%d",&(*p).age);
B.scanf("%s",&std.name);
C.scanf("%c",&std[0],sex)
D.scanf("%c",&(p->sex));