四川省计算机二级考试培训讲义(内部资料)
for(k=0;k<3;k++) {
w=f(w);
printf(“%d\\n”,w); } }
f(int x) {
int y=0; static z=3; y++;z++; return (x+y+z) ;
}
程序结束后,y的值为____B____。 (13) A 0 B 1 C 2 D 3
程序结束后,w的值为___A___。 (14) A 20 B 7 C 28 D 13 3.int x1=30,x2=40; main()
{
int x3=10,x4=20 ;
sub(x3,x4) ; sub(x2,x1);
L1:printf(“%d,%d,%d,%d\\n”,x3,x4,x1,x2); }
sub(int x, int y) {
x1=x ;x=y ;y=x1 ;
L2 :printf(“%d,%d\\n”,x,y) ; }
L1行输出结果为______D_________。
(15) A 10,20,30,40 B 10,20,40,10 C 20,10,40,30 D 10,20,40,40 L2行输出结果为_______B________。
(16) A 10,20 B 20,10 C 10,20 D 20,10
40,10 10,40 10,40 40,10
4.main() {
int x=1,i=1 ; for( ;x<50 ;i++) {
if(x>10) break ;
if(x%2 !=2) {x+=3 ;continue ;} x-=1 ;
- 14 -
四川省计算机二级考试培训讲义(内部资料)
}
printf(” %d\\n”,x) ; 17该语句输出为____D______。 printf(” %d\\n”,i) ; 18该语句输出为_____D______。 }
修订为: main() {
int x=1,i=1 ; for( ;x<50 ;i++) {
if(x>10) break ;
if(x%2 !=0) {x+=3 ;continue ;} x-=1 ; }
printf(\ // D printf(\ // D
}
(17) A 11 B 14 C 10 D 12 (18) A 7 B 8 C 9 D 10
5.以下程序不用第三个变量实现两个数对调的操作。程序中(19)为____A_____,(20)为____B______,(21)为____B______。 #includ
int a,b;
scanf(“%d,%d”&a,&b); a=_____A_____;(19) b=_____B_____;(20) c=______B____;(21) printf(“%d,%d”,a,b); }
修订为: #include
int a,b;
scanf(\ a=a+b; b=a-b;
a=a-b;
printf(\
}
(19) A a+b B a-b C a*b D a/b (20) A a+b B a-b C b-a D a*b
- 15 -
四川省计算机二级考试培训讲义(内部资料)
(21) A a+b B a-b C b*a D a/b 6.#include
void stringcat(char *s, char *t) {
int i=0,j=0;
while(*(s+i)) i++;
while(s[i++]=t[j++]);
} main() {
char s[]=”123”,t[]=”456”; stringcat(s,t); printf(“%s\\n”,s); }
修订为:
程序运行结果为:____C_____。
(22) A 123 B 456 C123456 D456123
在程序中,若将指针改为数组,stringcat函数的形式为: void stringcat(char s[], char t[]) {
int i=0,j=0;
while(*s[i]!=’\\0’) i++; while(s[i++]=t[j++]); }
修订为:
void stringcat(char s[], char t[]) {
int i=0,j=0;
while(s[i]!=’\\0’) i++; while(s[i++]=t[j++]); }
则程序运行后的结果为____C___。
(23) A 123 B 456 C 123456 D 456123 7.main() {
int x=10,y; y=x++;
printf(“%d,%d\\n”,(++x,y),y++);//表达式从右向左解 }
则程序运行后的结果为____D___。
- 16 -
四川省计算机二级考试培训讲义(内部资料)
(24) A 11,11 B 10,10 C 10,11 D 11,10 8.main() {
struct data { int i; float f;
double d;
union u{char u1[5]; long u2[2]; }ud; };
printf(“%d\\n”,sizeof(struct sata)); }
修订为:
#include \main() {
struct data {
int i;
float f; double d;
union u{char u1[5]; long u2[2]; }ud; };
printf(\}
程序运行结果为:_______C__。//按TC长度计算 (25) A 27 B 25 C 22 D 19 三程序填空(每小题2分,共30分)
1.下面程序删除字符串中的所有空格(包括TAB符,回车符、换行符)。请在程序的对应位置处填入。(函数isspace()用于测试字符是否为空格) #include
{
char str[81]={“1 2 3 4 5 6 7 8 9 ”}; delspace(str);
- 17 -
四川省计算机二级考试培训讲义(内部资料)
puts(str); }
delspace(str) char *str; { int i,t; char is[81];
for(i=0,t=0;____(26) str[i]或str[i]!=NULL 或str[i]=0 ____;_____(27) ++i或i++_____)
if(!isspace(____(28) *(str+i)或str[i]_____)) is[t++]=str[i]; is[t]=’\\0’; strcpy(str,is); }
//原型:extern int isspace(int c); // 用法:#include
// 说明:当c为空白符时,返回非零值,否则返回零。
// 空白符指空格、水平制表、垂直制表、换页、回车和换行符。
//从键盘输入五个字符组成的单词,判断该单词是不是hello,并显示结果。 #include
static char str[]={‘h’,’e’,’l’,’l’,’o’}; char str1[5];
int i,____(29) flag _____; for(i=0;i<5;i++)
str1[i]=____(30) getchar() ______; flag=0; for(i=0;i<5;i++)
if(str1[i]!=___(31) str[i] ___) {
flag=1; break;
- 18 -