练习一使用指向指针数据的指针变量输出指向的字符串
样例:
Follow me
BASIC
Great Wall
FORTRAN
Computer design
--------------------------------
Process exited after 0.02186 seconds with return value 0
请按任意键继续. . .
代码
//使用指向指针数据的指针变量
#include<stdio.h>
int main()
{
char *name[]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"};
char **p=name;
// for(;p<name+5;++p){
// printf("%s\n",*p);
// }
int i;
for(i=0;i<5;++i){
p=name+i;
printf("%s\n",*p);
}
return 0;
}
练习二:有一个指针数组,其元素分别指向一个整型数组的元素,用指向指针数据的指针变量来输出整型数组各元素的值。
输出样例:
The original array:
71 53 2 16 90 83 39 9 84 70
the array a:
71 53 2 16 90 83 39 9 84 70
--------------------------------
Process exited after 0.05449 seconds with return value 0
请按任意键继续. . .
代码段:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
srand((unsigned)time(NULL));
int a[10];
int *p=a;
printf("The original array:\n");
int i=0;
while(i<10){
*(p++)=rand()%100;
printf("%4d",a[i]);
++i;
}
int *pointer_a[10];
int **p1;
for(i=0;i<10;++i){
pointer_a[i]=&a[i];
}
printf("\n the array a:\n");
for(p1=pointer_a;p1<pointer_a+10;++p1){
printf("%4d",**p1);
}
return 0;
}