zoukankan      html  css  js  c++  java
  • 希望开发一个指针的元素

    <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>

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

  • 相关阅读:
    jQuery实现“回到顶部”按钮功能
    围绕DOM元素节点的增删改查
    jQuery ajax
    对JSON的理解
    Replacing Accented characters(Diacritic) .NET
    全球主要城市经纬度api
    无标题
    Use Razor for Email Template outside ASP.NET MVC
    .NET and php
    knockoutjs
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4746796.html
Copyright © 2011-2022 走看看