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

    一. 函数指针的定义:

      函数指针是指向函数的指针变量。 重点: 1. "函数指针" 是个变量, 变量类型是指针  2.指向函数

    二. 声明方法:

      返回值类 (* 函数指针变量名)(参数列表)

      例如:

      int func(int x);        //函数的声明

      int (*pFunc)(int x);    //函数指针的声明

      pFunc p = func;    //将func的首地址,赋值给函数指针p

      p = &func;

    二. 调用示例:

    #include <iostream>
    using namespace std;


    int add(int a, int b);    //函数声明
     
    struct p_fun {
        int (*pFunAdd) (int a, int b);  //函数指针定义
    };
     
    int main() {
        p_fun pFun;
        pFun.pFunAdd = add;

     cout<<"the result is :"<< pFun.pFunAdd(2,4);
        return 0;
    }

     
    int add(int a, int b) {   //函数定义
        return a + b;
    }

    函数指针一般应用在回调函数和多线程中

    https://blog.csdn.net/afei__/article/details/80549202

  • 相关阅读:
    php 时间问题
    php语言
    高级查询
    数据库的查询详情
    数据库的创建和增删改查,外键和主键的创建
    数据库
    js的基本语句和语法
    JS的脚本语言
    样式、格式布局
    表单的元素和样式表
  • 原文地址:https://www.cnblogs.com/darwen/p/12251463.html
Copyright © 2011-2022 走看看