C语言程序设计答案(黄保和编)第10章
厦门大学本科生公共课 《C程序设计基础》 教材习题答案 第10章 指针 一、 选择题
1. 设已定义“int a, * p”,下列赋值表达式中正确的是 :C)p=&a 2. 设已定义“int x,*p=&x;”,则下列表达式中错误的是:B)&*x
3. 若已定义“int a=1 ,*b=&a;”,则“printf;”的输出结果为:A) a的值。
4. 设已定义“int x,*p,*pl=&x,*p2=&x;”,则下列表达式中错误的是:C)p=p1+p2. 5. 设有函数定义“void p(int *x){printf(“%d\\\\n”,*x);}”和变量定义“int a=3;”,则正确的函数 调用是:C)p
6.
函
数
“
int
fun{char
*
y=x;
while(*y)y++;return(y-x); }”的功能是A)求字 符串的长度。
7. 运行一下程序,输出结果为:B)5 6 int fun (int a,int *b) { a++;++; return a+*b; } void main {int x=1,y=2;
Printf(“%d”,fun(x,&y)); Printf(“%d”,fun(x,&y)); } 8. 运行以下程序,输出结果为:C)58
#include Int * fun(int a ,int *b) {a++;(*b)++; *b=a+*b; return b; } Void main {
Int x=1,y=2,*z; Z=fun(x,&y); Printf(“%d”,*z); Z=fun(x,&y); Printf(“%d”,*z); }
9. 若已定义“int a={1,2 ,3,4},*p=a;”,则下面表达式中值不等于2的是C)*(++a) 10. 若已定义“int a={1,2 ,3,4},*p=a+1;”,则p[2]的值为C)4
11. 设已定义“int x[4][10],*p=x[0];”,则下列表达式中的值为整形的是B)* 12. 设已定义“char s=”ABCD”;”,”printf(“%s”,s+1)”的值为C)BCD 第1页/共7页
厦门大学本科生公共课 《C程序设计基础》 教材习题答案 第10章 指针
13. 设已定义“char str=”abcd”,*ptr=str;”,则*的值为B)0
14. 下面对字符串变量的初始化或赋值操作中,错误的是C)char a[10];a=”OK”; 15. 设已定义“char *ps[2]={“abc”,”1234”};”,则以下叙述中错误的是A)ps为指针变
量,它指向一个长度为2的字符串数组
16. 设已定义“struct {int a,b;} s,*ps=&s;”,则错误的结构体成员引用是C)* 17. 设已有以下定义,则表达式的值为2的是A)k=++p->data struct st { int data; st *link;
} a[3]={1,a+1,3,a+2,5,0},*p=a; 二、 编程题 1. 输入3个字符串,输出其中最大的字符串
#include #include #define str_count 3 #define str_length 100
int main(int argc, char *argv) {
char a[str_count][str_length],*p; printf(\\请输入3个字符串:\\ int i;
for(i=0;i #include #define pi 第2页/共7页
厦门大学本科生公共课 《C程序设计基础》 教材习题答案 第10章 指针
int main(int argc, char *argv) { double r;
printf(\\请输入半径:\\ scanf(\\ double c,s; void circle(double r, double *,double *); circle(r,&c,&s);
printf(\\圆的周长和半径分别为:%lf,%lf\\ system(\\