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));
        }
  • 相关阅读:
    The nineteenth day
    The eighteen day
    弱读下
    弱读上
    失爆 爆破音
    连读
    The seventeenth day
    The sixteenth day
    React 官方脚手架 create-react-app快速生成新项目
    pc端引入微信公众号文章
  • 原文地址:https://www.cnblogs.com/Winston/p/1142524.html
Copyright © 2011-2022 走看看