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

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

#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. Centos7 启动脚本

    Centos7 启动脚本 启动脚本.如果进程已存在,输出错误信息后退出: #! /bin/bash PIDS=`ps -ef | grep '/usr/bin/node ./index.js' | g ...

  2. go关键字之type用法

    1.定义结构体 type Student struct {     name string code int }       2.类型别名 type i int64 var age i = 30   ...

  3. git bash here右键菜单

    Windows Registry Editor Version 5.00 ; Open files[HKEY_CLASSES_ROOT\*\shell\gitbash]@="gitbash& ...

  4. 1.6 flask应用: 代码统计系统

    2019-1-6 15:57:18 今天的是做了一个代码统计的demo 使用了数据库的连接池 参考连接 https://www.cnblogs.com/wupeiqi/articles/8184686 ...

  5. poj 2826

    太自闭了...明明很水的说... 有三种为0的情况.一种是有水平,一种是没交点. 第三种有点难想啊.就是下面那个板子被上面的挡住了,,雨水进不去... 关键是我翻了翻discuss找到了这种数据,,但 ...

  6. Oracle管理常用查询语句

    1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom dba_tablespaces ...

  7. 把Oracle由归档模式改为非归档模式

    把Oracle由归档模式改为非归档模式 开始–>运行命令cmd进入命令行模式 1. 使用命令sqlplus以无日志形式打开如下: sqlplus /nolog; 2. 连接数据库dev.worl ...

  8. js监听手机端点击物理返回键或js监听pc端点击浏览器返回键

    之前在项目中遇到一个问题,就是在微信网页上面本来是有返回按钮的,但是大多数人都为了方便,会使用安卓手机自带的物理返回键,这个返回键按下后,就会按照你浏览器的栈存储的路径来一层一层返回,就不执行你页面上 ...

  9. 20.react库 入门

    vue插件: 使用方式:Vue.use(插件名称); {}/function 1.对象 export default { install(Vue,options){ } } 2.函数 export d ...

  10. 半夜两点灵光一现想出来的一个demo

    功能: 1.用户通过页面下载Excel模板,按照模板填写数据,上传Excel , 服务器解析 ,绘制成折线图.柱状图.雷达图 ....... 2.用户在线编辑数据,绘图 (没想好咋弄) 可定制需求,根 ...