通过函数名调用函数:

  int max = maxValue(4, 5);
  printf("max = %d\n", max);
    
  函数类型:int (int, int)

  1.定义函数指针

  int *p = NULL;

  函数类型:int (int, int)

  函数指针的类型:int (*)(int, int)

  p是函数指针变量名

  int (*p)(int, int) = NULL;

  2.给函数指针赋值(使用函数首地址)

  函数存放在代码区,函数名是函数存储空间的首地址

  p = maxValue;

  3.通过函数指针调用函数和通过函数名调用函数一样。

  动态排序:

  使用回调函数,提高代码的复用性,提高代码的可修改性(当需求有变化时,可以快速简单的修改)

  

 Function.h
 struct student {

     ];  // 姓名
     int age;        // 年龄
     double score;   // 成绩
     int num;        // 学号

 };
 typedef
 // 打印所有学生的信息
 void printArray(Student stuArray[], int count);

 // 比较两个学生的年龄
 BOOL compareStuAge(Student stu1, Student stu2);

 // 比较两个学生的姓名
 BOOL compareStuName(Student stu1, Student stu2);

 // 比较两个学生的成绩
 BOOL compareStuScore(Student stu1, Student stu2);

 // 比价两个学生的学号
 BOOL compareStuNum(Student stu1, Student stu2);

 typedef BOOL (*FUNC)(Student, Student);

 // 排序函数
 void sortStudent(Student *stu, int count, FUNC p);
 Function.m

 // 比较两个学生的年龄
 BOOL compareStuAge(Student stu1, Student stu2) {
     return stu1.age > stu2.age;
 }

 // 比较两个学生的姓名
 BOOL compareStuName(Student stu1, Student stu2) {
     ;
 }

 // 比较两个学生的成绩
 BOOL compareStuScore(Student stu1, Student stu2) {
     return stu1.score < stu2.score;
 }

 // 比价两个学生的学号
 BOOL compareStuNum(Student stu1, Student stu2) {
     return stu1.num > stu2.num;
 }

 // 排序函数
 void sortStudent(Student *stu, int count, FUNC p) {

     ; i < count - ; i++) {
         ; j < count -  - i; j++) {
             ])) {
                 Student temp = stu[j];
                 stu[j] = stu[j + ];
                 stu[j + ] = temp;
             }
         }
     }
 }
 main.m
 int main(int argc, const char * argv[]) {

     Student stu1 = {, };
     Student stu2 = {, , };
     Student stu3 = {, -, };
     Student stu4 = {, , };
     Student stu5 = {, , };

     Student stuArray[] = {stu1, stu2, stu3, stu4, stu5};
     int count = sizeof(stuArray) / sizeof(Student);
 // 动态排序
     sortStudent(stuArray, count, compareStuNum);
     printArray(stuArray, count);
     sortStudent(stuArray, count, compareStuAge);
     printArray(stuArray, count);
     sortStudent(stuArray, count, compareStuName);
     printArray(stuArray, count);
     sortStudent(stuArray, count, compareStuScore);
     printArray(stuArray, count);

iOS学习之C语言函数指针的更多相关文章

  1. IOS学习笔记07---C语言函数-printf函数

    IOS学习笔记07---C语言函数-printf函数 0 7.C语言5-printf函数 ------------------------- ----------------------------- ...

  2. IOS学习笔记06---C语言函数

    IOS学习笔记06---C语言函数 --------------------------------------------  qq交流群:创梦技术交流群:251572072              ...

  3. iOS学习之C语言函数

    一.函数的定义 返回值类型 函数名(参数类型 参数名, ...) { 功能语句; return 返回值; } 按照返回值和参数划分: 第一种: 无返回值 无参 void sayHello() { pr ...

  4. C#委托与C语言函数指针及函数指针数组

    C#委托与C语言函数指针及函数指针数组 在使用C#时总会为委托而感到疑惑,但现在总新温习了一遍C语言后,才真正理解的委托. 其实委托就类似于C/C++里的函数指针,在函数传参时传递的是函数指针,在调用 ...

  5. C语言函数指针 和 OC-Block

    C语言函数指针 和 OC-Block 一. C语言函数指针 关于函数指针的知识详细可参考:http://www.cnblogs.com/mjios/archive/2013/03/19/2967037 ...

  6. C语言函数指针基础

    本文写的非常详细,因为我想为初学者建立一个意识模型,来帮助他们理解函数指针的语法和基础.如果你不讨厌事无巨细,请尽情阅读吧. 函数指针虽然在语法上让人有些迷惑,但不失为一种有趣而强大的工具.本文将从C ...

  7. “对外部(局部)变量的访问”是C语言函数指针的最大弱点

    1.“对外部(局部)变量的访问”是C语言函数指针的最大弱点 . #include <stdio.h> #include <stdlib.h> /* 结构体定义 */ struc ...

  8. iOS学习09C语言函数指针

    本次主要学习和理解函数指针 1.函数指针 void printValue(int number) { printf("number = %d\n", number); } int ...

  9. c语言函数指针的理解与使用(学习)

    1.函数指针的定义 顾名思义,函数指针就是函数的指针.它是一个指针,指向一个函数.看例子: 1 2 3 A) char * (*fun1)(char * p1,char * p2); B) char  ...

随机推荐

  1. 使用.NET MVC框架项目开发流程(项目开发流程)

    MVC项目开发流程 整理需求,进行需求分析.项目设计. 整理数据项,建数据库做前期准备,并整理字典. 建立所需数据库表和视图和模型. 页面实现其初步功能(跳过逻辑后台代码),只是实现页面之间的跳转以及 ...

  2. session StateServer 方式 初始化StateServer服务器

    1.初始化StateServer服务器启动ASP.NET 状态服务[aspnet_state],该服务默认是手动启动的,可以通过修改注册表,设置为自动启动并允许远程连接.修改方法如下:修改注册表: [ ...

  3. HBase -ROOT-和.META.表结构

    在HBase中,大部分的操作都是在RegionServer完成的,Client端想要插入,删除,查询数据都需要先找到相应的RegionServer.什么叫相应的RegionServer?就是管理你要操 ...

  4. linux ---用uniq实现文件的并集和交集

    1. 取出两个文件的并集(重复的行只保留一份) 2. 取出两个文件的交集(只留下同时存在于两个文件中的文件) 3. 删除交集,留下其他的行 1. cat file1 file2 | sort | un ...

  5. EPPB also support BlackBerry device

    各位看倌不是小弟要賣弄英文,實在是外國朋友希望知道上一篇"雲取證"中所用的工具Elcomsoft Phone Password Breaker支援黑莓機否?又要求非要看到截屏才算數 ...

  6. ArrayList总结

    ArrayList 1.extends AbstractList 实现List<E>->Collection<e>->Iterable,RandomAccess,S ...

  7. leetcode 21

    合并两个有序数列.属于基础的数据结构问题,核心在于对链表的操作. 代码如下: /** * Definition for singly-linked list. * struct ListNode { ...

  8. PowerDesigner生成Oracle数据字典

    PowerDesigner版本信息 1.File-->NewModel... 2.选择模型 New Model Model types-->Physical Data Model --&g ...

  9. javascript 详解数组

      概念 数组创建 数组读写 数组 VS. 一般对象 相同点 不同点 稀疏数组 数组的length属性 元素增删 数组迭代 二维数组 数组方法 Array.prototype.join Array.p ...

  10. Android IOS WebRTC 音视频开发总结(四一)-- QQ和webrtc打洞能力pk

    很多人知道webrtc打洞能力很强,到底有多强但是不知道,比较好的方法就是跟QQ对比,但大多数公司很难模拟各种网络环境进行测试,比如联通,铁通,电信,移动,所以这次请小师妹在实验室下进行了一个比较全面 ...