
《C语言程序设计》课件chapter6answer.doc
2页第六章 指针参考答案一、选择题(把正确选项的字母标号填到表格中)题号1234567891011121314151617181920答案CDADDBDDAAACADCBDBCC- 2 -二、判断题(错的填×,对的填√)题号1234567891011121314151617181920答案√√×√××√×√√√√××√√×√√×三、应用题1.根据要求把实现相关功能的语句填在表格中已知条件要求实现的语句int x;int a[5]={1,2,3,4,5};int *p;定义指针px并指向xint *px = &x;定义二级指针ppx并间接指向xint *ppx = &px;通过px为x输入数据的scanfscanf(“%d”,px);通过ppx输出x值的printfprintf(“%d\n”,**ppx);定义指针p1指向a[0]int *p1 = a; 或int *p1 = &a[0];定义指针p2指向a[3]int *p2 = &a[3];通过p动态分配一个存整数的空间p =(int *)malloc(sizeof(int));2.根据已知条件,把给定语句的输出结果写在表格中已知条件语句语句输出结果int a[ ]= {1,2,3,4,5};int *p = a;printf(“%d\n”,*a);1printf(“%d\n”,*&a[2]);3printf(“%d\n”,*p);1printf(“%d\n”,*(p+1));2printf(“%d\n”,*p+1);23.根据已知条件,把给定语句的输出结果写在表格中。
已知条件语句语句输出结果int a[][3]= {1,2,3,4,5,6,7,8,9};int (*p)[3] = a;printf(“%d\n”,*p[0]);1printf(“%d\n”,*a[2]);7printf(“%d\n”,*(p[2]+1));8printf(“%d\n”,*(*p+1));2printf(“%d\n”,*(*(p+1)+2));6四、编程题1. #include "stdio.h"int main(void){ int x, *px = &x; float y, *py = &y; float **mul = &py; printf("Enter an integer: "); scanf("%d",px); printf("Enter a real number: "); scanf("%f",py); printf("%d*%.3f=",*px,*py); **mul *= *px; printf("%.2f\n",**mul); return 0;} 2. #include "stdio.h"#define N 10int main(void){ int a[N] = {1,2,3,4,5,6,7,8,9,10}; int i; int *p = a; float aver = 0; for(i=0;i
