zoukankan      html  css  js  c++  java
  • 函数指针小结

    1. 函数指针指指向函数的指针,强调指针,函数名是内存中的起始地址。

      格式为:int (*fun)(int,int)。

    2. 指针函数强调函数,指返回值是指针类型的函数。指针函数常见,不再具体说明。

      格式为:int *fun(int,int);

      #include <stdio.h>
               
      #define N 10
               
      /*函数指针指指向函数的指针,强调指针,函数名是内存中的起始地址。
      格式为:int (*fun)(int,int)。
      而指针函数强调函数,指返回值是指针类型的函数。
      格式为:int *fun(int,int);*/
      void swap(int *x,int *y)//交换
      {
          int t = *x;
          *x = *y;
          *y = t;
      }
               
      int asc(int a,int b)//递增
      {
          return a > b ? 1 : 0;
      }
               
      int des(int a,int b)//递减
      {
          return a < b ? 1 : 0;
      }
               
      void bubblesort(int a[],int n,int (*compare) (int,int))//函数指针
      {
          int i,j;
          for(i = 0; i< n;i++)
          {
              for(j = 0; j < n-i-1;j++)
              {
                  if((*compare)(a[j],a[j+1]))
                      swap(&a[j],&a[j+1]);
              }
          }
      }
               
      void display(int a[],int n)
      {
          int i;
          for(i = 0; i< n;i++)
              printf("%-4d",a[i]);
          printf("
      ");
      }
               
      int main()
      {
          int a[N] = {2,1,5,3,4,7,8,6,10,9};
          bubblesort(a,N,asc);
          display(a,N);
          bubblesort(a,N,des);
          display(a,N);
          return 0;
      }
  • 相关阅读:
    tornado简单的验证码
    python分页和session和计算时间差
    初始tornado框架
    Jquery小实例
    DOM+Javascript一些实例
    Javascript
    CSS拾遗+技巧集合
    css样式基础
    KVM NAT网络模式配置
    Ultimate guide to learning AngularJS in one day
  • 原文地址:https://www.cnblogs.com/zxy1992/p/3452400.html
Copyright © 2011-2022 走看看