1、第六章 指针参考答案一、选择题(把正确选项的字母标号填到表格中)题号1234567891011121314151617181920答案CDADDBDDAAACADCBDBCC- 2 -二、判断题(错的填,对的填)题号1234567891011121314151617181920答案三、应用题1.根据要求把实现相关功能的语句填在表格中。已知条件要求实现的语句int x;int a5=1,2,3,4,5;int *p;定义指针px并指向xint *px = &x;定义二级指针ppx并间接指向xint *ppx = &px;通过px为x输入数据的scanfscanf(“%d”,px);通过ppx输出
2、x值的printfprintf(“%dn”,*ppx);定义指针p1指向a0int *p1 = a; 或int *p1 = &a0;定义指针p2指向a3int *p2 = &a3;通过p动态分配一个存整数的空间p =(int *)malloc(sizeof(int);2根据已知条件,把给定语句的输出结果写在表格中。已知条件语句语句输出结果int a = 1,2,3,4,5;int *p = a;printf(“%dn”,*a);1printf(“%dn”,*&a2);3printf(“%dn”,*p);1printf(“%dn”,*(p+1);2printf(“%dn”,*p+1);23根据已
3、知条件,把给定语句的输出结果写在表格中。已知条件语句语句输出结果int a3= 1,2,3,4,5,6,7,8,9;int (*p)3 = a;printf(“%dn”,*p0);1printf(“%dn”,*a2);7printf(“%dn”,*(p2+1);8printf(“%dn”,*(*p+1);2printf(“%dn”,*(*(p+1)+2);6四、编程题1. #include stdio.hint main(void)int x, *px = &x;float y, *py = &y;float *mul = &py;printf(Enter an integer: );scan
4、f(%d,px);printf(Enter a real number: );scanf(%f,py);printf(%d*%.3f=,*px,*py);*mul *= *px;printf(%.2fn,*mul);return 0; 2. #include stdio.h#define N 10int main(void)int aN = 1,2,3,4,5,6,7,8,9,10;int i;int *p = a;float aver = 0;for(i=0;iN;i+)aver += *(p+i);aver /= N;printf(Average of array a is %.1fn,aver);return 0;