有以下程序:struct s{ int x,y; }data[2]={10,100,20,200};main(){ struct s *p=data;printf("%d\n",(p)->x);}程序运行后的输出结果是()。
A.10
B.11
C.20
D.21
C、20
解析:结构体;struct s *p=data; 使p指向data的首地址,而++p->x,先使p指向下一位即20,然后输出其值。
A.10
B.11
C.20
D.21
C、20
解析:结构体;struct s *p=data; 使p指向data的首地址,而++p->x,先使p指向下一位即20,然后输出其值。
第1题
有以下程序
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
第2题
A.S 是结构体名
B. 该结构体包含 2 个成员
C. S 是 struct 类型的变量
D. T 是 struct S 类型的变量
第3题
阅读以下说明和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);
}
第4题
已知学生记录描述为: 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;
第5题
A.10
B.11
C.51
D.60
第6题
第7题
程序: #include <stdio.h> #include <string.h> typedef struct{char name[9];char sex;float score[2]}STU; STU f(STU A) {STU b={"Zhao",'m',85.0,90.0}; int i; strcpy(a.name,b.namC) ; a.sex=b.sex; for(i=0;i<2;i++) a.score[i]=b.score[i]; return a; } main() {STU c={"Qian",'f',95.0,92.0},d; d=f(C) ; pintf("%s,%c,%2.of.%2.of\n",d.name,d.sex,d.score[0],&score[1]); } 程序的运行结果是()。
A.Qian,f,95,92
B.Qian,m,85,90
C.Zhao,m,85,90
D.Zhao,C95,92
第8题
有以下程序
#include<stdio.h>
void fun(int *s)
{ static int j=0;
do { s[j]=s[j]+s[j+1]; )while(j<2);
}
main()
{ int k,a[10]={1,2,3,4,5);
for(k=1;k<3;k++)fun(a);
for(k=0;k<5;k++)printf(”%d”,a[k]);
printf("\n");
}
程序运行后的输出结果是
A) 12345
B)23445
C)34756
D) 35745
第9题
A.409
B.277
C.1
D.91
第10题
有以下程序: #include <stdio.h> int fun(int x[], int n) { static int sum =0,i; for(i=0;i<n;i ++ )sum + =x[i]; return sum;{ int a[] ={1,2,3,4,5},b[]={6,7,8,9},s=0; s = fun(a,5) + fun(b,4) ;printf("%d \n",s);程序执行后的输出结果是()。
A.45
B.50
C.60
D.55