函数指针:函数指针数组的使用:

不带参数和返回值的函数指针:

#include <stdio.h>
#include <stdlib.h>

//定义一个没有返回值也没有入口参数的函数指针
typedef void (CONTROL_FLOW_FUNCTION)();

void Function1()
{
    printf("  This is printed by function1 !!!\n");
}
void Function2()
{
    printf("  22222222\n");
    printf("    22222222\n");
}
void Function3()
{
    printf("  This is printed by function3......\n");
}

CONTROL_FLOW_FUNCTION *ControlFlowFunctions[] = {
    Function1,
    Function2,
    Function3,
    NULL
};

char *ControlFlowFunctionNames[] = {
    "Function1",
    "Function2",
    "Function3",
    NULL
};

int main()
{
    ;
    printf("main start!\n");
    ; ControlFlowFunctions[i]!=NULL; i++){
        printf("ControlFlow.%s\n", ControlFlowFunctionNames[i]);
        ControlFlowFunctions[i]();
    }
    printf("main end!\n");
}

带参数和返回值的函数指针:

#include <stdio.h>
#include <stdlib.h>

//定义一个函数指针类型
typedef int (CONTROL_FILTER_FUNCTION)(int dat);

int Function1(int data)
{
    printf("Check if data can be exactly divisible by 2.\n");
     == )
        ;
    else
        ;
}
int Function2(int data)
{
    printf("Check if data can be exactly divisible by 3.\n");
     == )
        ;
    else
        ;
}
int Function3(int data)
{
    printf("Check if data can be exactly divisible by 5.\n");
     == )
        ;
    else
        ;
}

CONTROL_FILTER_FUNCTION *ControlFilterFunctions[] = {
    Function1,
    Function2,
    Function3,
    NULL
};

char *ControlFilterFunctionNames[] = {
    "Function1",
    "Function2",
    "Function3",
    NULL
};

int main()
{
    ;
    ;
    printf("==Check if data can be exactly divisible by 2 or 3 or 5==.\n");
    ; ControlFilterFunctions[i]!=NULL; i++){
        printf("ControlFilter.%s\n", ControlFilterFunctionNames[i]);
        if(ControlFilterFunctions[i](data))
        {
            printf("YES::%d can be exactly divisible by 2 or 3 or 5.\n", data);
            ;
        }
    }
    printf("NO::%d can't be exactly divisible by 2 or 3 or 5.\n", data);
    ;
}

C语言实例:函数指针的更多相关文章

  1. c语言之函数指针应用

    c语言之函数指针应用 1.函数指针与指针函数 在开始运用函数指针前,我们需要将两个概念即:函数指针与指针函数搞清楚. 函数指针,指明这个一个函数,但返回值为指针类型,语法格式为: 类型名* 函数名A( ...

  2. c语言之函数指针

    一.基础研究 这里研究的内容是函数指针,需要我们在研究后构造程序来描述函数指针数组的用法和向函数传函数指针的方法. 指针有很多种:整型指针.结构体指针.数组指针等等,它们的本质是它们的值都是一个地址, ...

  3. 谈谈自己对C语言中函数指针的一些理解 (第一次写博客,有点小兴奋哈)

    1.函数指针声明的格式及简单的使用 (1)格式:(返回值)(*函数指针名)(参数列表)    例如:声明一个无参数无返回值的函数指针(void)(*p)(void). (2)将函数指针指向某个无参数无 ...

  4. C语言的函数指针数组(好绕啊~看完这篇估计就通关了)

    转自https://www.cnblogs.com/chr-wonder/p/5168858.html int *(*p(int))[3] 今天有人问这个是啥?我一看直接就懵逼了…… 下面做一些简单的 ...

  5. C语言基础:函数指针 分类: iOS学习 c语言基础 2015-06-10 21:55 15人阅读 评论(0) 收藏

    函数指针:指向函数的指针变量. 函数名相当于首地址. 函数指针定义:返回值类型  (*函数指针变量名)(参数类型1,参数类型2,....)=初始值 函数指针类型:返回值类型  (*)(参数类型1,参数 ...

  6. c语言定义函数指针和typedef简写

    二种方法来定义函数指针 #include<stdio.h> #include<stdlib.h> #include<Windows.h> int add(int a ...

  7. C语言之函数指针、回调函数的使用

    一.背景 首先看下如下代码,这个定义是放在头文件的,在程序中tCdrvCallbackFkt也定义了另一个变量,而且括号后面还跟定义了几个变量,不理解这个定义. typedef void (PUBLI ...

  8. c语言的函数指针和函数指针数组的简单demo

    今天,简单记录一下,函数指针和函数指针数组的使用,废话不多说,直接贴上代码,里面有详细的注释,方便以后查阅. #include <cstdio> #include <Windows. ...

  9. c语言的函数指针

    简单定义并间接调用 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<time.h> void singas ...

  10. 可读性很强的C语言的函数指针定义

    通常C/C++程序里面要用到大量的指针,其语法非常难以阅读.比如下面的vp指针类型: #include <iostream> using namespace std; typedef vo ...

随机推荐

  1. 【转】Android 为什么 dp2px 或 px2dp 公式需要加 0.5f

    转自:http://blog.csdn.net/changcsw/article/details/52440543 网上 dp2px 和 px2dp 公式: public static int px2 ...

  2. vue.js学习资料

    vue.js学习VuejsAPI教程 https://vuejs.org.cn/guide/Vuejs自己的构建工具 http://www.jianshu.com/p/f8e21d87a572如何用v ...

  3. Mysql order by与limit混用陷阱

    在Mysql中我们常常用order by来进行排序,使用limit来进行分页,当需要先排序后分页时我们往往使用类似的写法select * from 表名 order by 排序字段 limt M,N. ...

  4. J - Network of Schools

    来源poj1236 A number of schools are connected to a computer network. Agreements have been developed am ...

  5. 从javaScript中学习正则表达式——RegExp

    正则表达式工具:http://regexper.com   由于国外网络可以选择 https://github.com/javallone/regexper-static 离线安装作为本地服务. 正则 ...

  6. 初始easyUI

    1 easyUI布局 <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...

  7. 再次重温《Right here waiting》

    记得高中时候听到这首曲子(当时还让同桌帮我抄了这首曲子,后来这个本子也不知道扔到哪里去了), 前天偶尔在虾米遇到这首曲子,过去的青涩岁月历历在目,自己手动打打歌词,一方面是为了重温这首曲子,另一方面, ...

  8. Chrome 调试技巧

    Chrome 调试技巧 1.alert 这个不用多说了,不言自明. 可参考:https://www.cnblogs.com/Michelle20180227/p/9110028.html 2.cons ...

  9. Java ee第七周作业

    一.什么是JSON?JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度. JSON就是一串字符串 只不过元素会使用特定的 ...

  10. python 中的__new__与__init__

    在Python中的class中有两个方法__new__与__init__,有什么区别呢? class TestCls(): """docstring for TestCl ...