zoukankan      html  css  js  c++  java
  • C/C++ Basicsfunction pointer

    1.basic concepts
        function pointer in C/C++ is just like delegate in C#. we can use function pointer to point to a specific function, and then use function pointer to invoke the specified function.
        eg.
        int max(int a,int b)
        {
        return a>b?a:b;
        }

        void main()
        {
        int (*p)(int,int); //declare a function pointer
        p=max;//the function point must has the same return type and parameter type with specified function.
        printf("max(2,3) is %d",p(2,3));
        }
        //the result is 3;

    also , we can use typedef to define a function pointer type to simplify the programming.
    eg.
        #typedef int (*MyFunPointer)(int a,int b);
        //we define a function pointer type which has int return type and has two int parameters.
        void main()
        {
        MyFunPointer p;
        p=max;
        printf("max(2,3) is %d",p(2,3));
        }
  • 相关阅读:
    nginx 相关命令
    uni-app跨域解决
    vue-cli3.0的项目搭建
    vue.js
    Flex布局
    javascript 数组排重
    IE的hack问题浅谈
    div自身高度、屏幕高度
    bootstrap轮播和百叶窗
    面向对象
  • 原文地址:https://www.cnblogs.com/Winston/p/1142524.html
Copyright © 2011-2022 走看看