希望开发一个指针的元素
<span style="font-size:18px;">#include<stdio.h>
int search(int *apt,int n,int key)/*数组中的退货和key相等值的下标*/
{
int *p;
for(p=apt;p<apt+n;p++)
{
if(*p==key)
return p-apt;
}
return NULL;/*不能够在if以下直接else,由于得循环找出和key值同样的值。遍历完了发现没有才返回null*/
}
int *find(int *apt,int n,int key)/*返回在数组中和key值相等值的地址*/
{
int *p;
for(p=apt;p<apt+n;p++)
{
if(*p==key)
return p;
}
return NULL;
}
void main()
{
int a[]={2,3,7,0,5,24,67,45,90,6,1,8,88};
int key,i;
for(i=0;i<sizeof(a)/sizeof(int);i++)
printf("%4d",a[i]);
printf("\n");
printf("please input the key number!\n");
scanf("%d",&key);
printf("The address of a[0] is: %d.\n",a);
printf("The label number of the key number in the array is %d\n",search(a,sizeof(a)/sizeof(int),key));
printf("The adress of the key number %d\n",find(a,sizeof(a)/sizeof(int),key));
}</span>版权声明:本文博客原创文章,博客,未经同意,不得转载。
浙公网安备 33010602011771号