有以下程序: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,然后输出其值。
有以下程序
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
有以下程序
#include<stdlib.h>
struct NODE
{int num;struct NODE*next;}
main()
{struct NODE *P,*q,*r;
p=(struct NODE *)malloc(sizeof(struct NODE));
q=(struct NODE *)malloc(sizeof(struet NODE));
r=(struct NODE*)malloc(sizeof(struct NODE)):
p->num=10;q->num=20;r->num=30;
p->next=q;q->next=r;
printf("%d\n",p->num+q->next->num):
}
程序运行后的输出结果是()
A.10
B.20
C.30
D.40
有以下程序: struct STU{ char name[10]; int num; }; void f1(struct STU c) { struct STU b={"LiSiGuo",2042); c=b; } void f2(struct STU *c) { struct STU b={"SunDan",2044); *c=b; } main() {struct STU a={"YangSan",2041},b={"WangYin",2043); f1(a);f2(&b); printf("%d %d\n",a.num,b.num); } 执行后输出结果是()。
A.2041 2044
B.2041 2043
C.2042 2044
D.2042 2043
阅读以下说明和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);
}
若有以下语句: typedef struct S {int g;char h;}T; 以下叙述中正确的是()。
A.可用S定义结构体变量
B.可用T定义结构体变量
C.S是struct类型的变量
D.T是struct S类型的变量
A.10,20,20
B.50,60,21
C.51,60,21
D.60,70,31
A.0
B.10
C.30
D.64
有以下程序:#include <stdio.h>main(){ int i,s=0,t[] = {1,2,3,4,5,6,7,8,9}; for(i=0;i<9;i+=2) s+=*(t+i); prinff("% d \n ",s);
A.45
B.20
C.25
D.36
有以下程序
#include<stdio.h>
#define S(x)4*(x)*x+1
main()
{int k=5,j=2;
printf(“%d\n”,S(k+j));
}
程序运行后的输出结果是
A.197
B.143
C.33
D.28