函数指针&指针函数

https://blog.csdn.net/luoyayun361/article/details/80428882

#include <iostream>
using namespace std;


void * func(int a)           //指针函数,实质是一个函数,返回值是指针类型;
{
    static int c = a;
    return &c;
}

void test(int a)
{
    cout << "test" << a << endl;
}

typedef void (*p) (int);    //函数指针,实质是一种类型,此处的类型表示,无返回值,形参为int类型的函数类型

int main(int argc, char** argv)
{
    p a = test;             //test函数名,本身就表示地址;可直接赋值;
    (*a)(10);               //调用函数:方法一 ;
    a(100);                 //调用函数:方法二; 两种方法都可以;

    p b = &test;
    (*b)(9);
    b(99);
    system("pause");
    return 0;
}

 

posted @ 2019-03-14 11:13  唯一诺  阅读(164)  评论(0编辑  收藏  举报