#include
void fun( char *w, int m) { char s, *p1, *p2;
p1 = w; p2 = w+m-1; while(p1 < p2) { s = *p1 ++;
*p1 = *p2--; *p2 = s; }
}
void main()
{ char a[] = “ABCDEFG”;
fun(a, strlen(a)); puts(a);
}
A)GFEDCBA B)AGADAGA C)AGAAGAG D)GAGGAGA A34.以下程序的输出结果是
A)ABCD B)A C)D D)ABCD BCD B C ABC CD C B AB D D A A void main()
{ char s[] = “ABCD”, *p;
for(p = s; p < s + 4; p++) printf(“%s\\n”, p);
}
B35.设有如下定义:
char *aa[2] = { “abcd”, “ABCD“}; 则以下说法中正确的是
A)aa数组元素的值分别是”abcd”和ABCD”
B)aa是指针变量,它指向含有两个数组元素的字符型一维数组
C)aa数组的两个元素分别存放的是含有四个字符的一维数组的首地址 D)aa数组的两个元素中各自存放了字符’a’和’A’的地址 A36.以下程序的输出结果是 void main()
{ char ch[2][5] = {“6937”, “8254”}, *p[2];
int i, j, s = 0;
for(i = 0; i < 2; i++) p[i] = ch[i]; for(i = 0; i < 2; i++)
for(j = 0; p[i][j] > ‘\\0’ && p[i][j] <= ‘9’; j += 2) s = 10 * s+ p[i][j] - ‘0’; pritnf(“%d\\n”, s);
41
}
A)6385 B)69825 C)63825 D)693825 C37.以下程序的输出结果是 void main()
{ char *alpha[6] = {“ABCD”,”EFGH”,”iJKL”,”MNOP”,”QRST”,”UVWX”};
char **p; int i; p = alpha;
for(i = 0; i < 4; i++) printf(”%s”, p[i]); printf(“\\n”);
}
A)ABCDEFGHiJKL B)ABCD C)ABCDEFGHiJKLMNOP D)AEiM
C38.库函数strcpy用以复制字符串。若有以下定义和语句: char str[] = “string”, str2[8], *str3, *str4 = “string”; 则对库函数strcpy的不正确调用是
A)strcpy(str1, “HELLO1”); B)strcpy(str2, “HELLO2”); C)strcpy(str3, “HELLO3”); D)strcpy(str4, “HELLO4”);
D39. 设有定义:int n=0,*p=&n,**q=&p,则下列选项中正确的赋值语句是
A)p=1; B)*q=2; C)q=p; D)*p=5; 二、填空题
1.以下程序段的输出结果是 110 。 int *var, ab;
ab = 100; var = &ab; ab = *var + 10; printf(“%d\\n”, *var);
2.以下程序的输出结果是 7 1 。 int ast(int x, int y, int *cp, int *dp) { *cp = x + y;
*dp = x - y;
}
void main()
{ int a, b, c, d;
a = 4; b = 3; ast(a, b, &c, &d);
printf(“%d %d\\n”, c, d);
}
3.若有定义: char ch;
(1) 使指针p可以指向变量ch的定义语句是 char*p=&ch ; 。 (2) 使指针p指向变量ch的赋值语句是 p=&ch; 。
(3) 通过指针p给变量ch读入字符的scanf函数调用语句是 scanf(“%c”, p); 。 (4) 通过指针p给变量ch赋字符的语句是 *p=’a’ 。 (5) 通过指针p输出ch中字符的语句是 putchar(*p) 。
42
4.以下程序的输出结果是 6 。 void main()
{ int a[] = {2, 4, 6}, *prt = &a[ 0], x = 8, y, z;
for(y = 0; y < 3; y++)
z = (*(prt + y) < x ) ? *(prt + y) : x; printf(“%d\\n”, z);
}
5.以下程序的输出结果是 3 。 #define N 5
fun( char *s, char a, int n) { int j;
*s = a; j = n; while( a < s[j] )
j--; return j;
}
void main()
{ char s[N+1]; int k, p;
for(k = 1; k <= N; k++) s[k] = ‘A’ + k + 1;
printf(“%d\\n”, fun(s, ‘E’, N) );
}
6. 以下程序的输出结果是 GFEDCB 。
#include “stdio.h” void main()
{ char b[] = “ABCDEFG”, *chp = &b[7]; while( --chp >&b[0] )
putchar (*chp);
putchar (‘\\n’); }
7. 以下程序的输出结果是 XYZA 。
#include “stdio.h”
void fun(char *a1, char *a2, int n) { int k;
for(k = 0; k < n; k++)
a2[k] = (a1[k] - ‘A’ - 3 + 26) % 26 + ‘A’; a2[ n ] = ‘\\0’; }
void main()
{ char s1[5] = “ABCD”, s2[ 5 ]; fun(s1, s2, 4); puts(s2); }
8. 以下程序的输出结果是 SO 。
43
void main()
{ char *p[] = {“BOOL”, “OPK”, “H”, “SP”}; int i;
for(i = 3; i >= 0; i--, i--)
printf(“%c”, *p[i]); printf(“\\n”); }
9. 当运行以下程序时从键盘输入字符串qwerty和abcd, 则程序的输出结果是 10 。
#include “string.h” #include “stdio.h”
strle(char a[], char b[]) { int num = 0, n = 0;
while( *(a + num) != ‘\\0’)
num ++; while(b[n])
{ *(a+num) = b[n];
num ++; n++; }
return (num); }
void main()
{ char str1[81], str2[81], *p1 = str1, *p2 = str2; gets(p1); gets(p2);
printf(“%d\\n”, strle(p1, p2)); }
10. 以下程序段的输出结果是 gooddog 。
char s[20] = “gooddog!”, *sp = s; sp = sp +2; sp = “to”; puts(s);
11.假定以下程序经编译和链接后生成可执行文件PROG.EXE,如果在DOS提示符下键入
PROG ABCD EFGH iJKL
则输出结果为: i JKLEFGHABCD 。
void main()
{ while( -- argc > 0 )
printf(“%s”, argv[argc] ); printf(“\\n”); }
12.以下程序的输出结果是 8 。
fun( int n , int *s) { int f1, f2;
if( n == 1 || n == 2) *s = 1;
44
else
{ fun( n - 1, &f1) ; fun(n - 2, &f2); *s = f1 + f2; } }
void main() { int x; fun(6, &x);
printf(“%d\\n”, x ); }
13.以下程序调用invert函数按逆序重新放置a数组中元素的值,a数组中的值在void main函数中读入。请填空。
#define N 10
void invert( int *s, int i, int j) { int t; if(i < j)
{ t = *(s + i);
*(s + i ) = *(s+j) ; *(s + j ) = t;
invert( s, i+1 , j - 1); } }
void main() { int a[N], i;
for( i = 0; i < N; i++)
scanf(“%d”, a + i ); invert( a, 0, N - 1); for(i = 0; i < N; i ++) printf(“%d”, a[i]); printf(“\\n”); }
14.以下程序的输出结果是 17 。
funa( int a, int b ) { return a + b; }
funb( int a, int b) { return a - b; }
sub( int (*t)(), int x, int y) { return (*t) (x, y ); }
void main()
{ int x, (*p)( int, int);
45