希望开发一个指针的元素

<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("
");
	printf("please input the key number!
");
	scanf("%d",&key);
	printf("The address of a[0] is: %d.
",a);
	printf("The label number of the key number in the array is %d
",search(a,sizeof(a)/sizeof(int),key));
	printf("The adress of the key number %d
",find(a,sizeof(a)/sizeof(int),key));
}</span>

版权声明:本文博客原创文章,博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/gcczhongduan/p/4746796.html