函数指针和指针函数

来源:互联网 发布:恒大淘宝足球吧 编辑:程序博客网 时间:2024/06/06 09:56

函数指针和指针函数

 

[user:函数指针和指针函数] cat main.cpp
/// @file main.cpp
/// @brief
/// @author EastonWoo
/// 0.01
/// @date 2013-04-30

#include <stdio.h>

//函数指针(先指针,后函数)
#define FUNC(pf) int(*pf)(int, int)=NULL;
typedef int(*F_FUNC)(int, int);  //分号要保留


//指针函数(先函数,后指针)(返回值是指针)
typedef int*((*FF)(int&));


int func(int a, int b)
{
    return (a + b); 
}

int* ffunc(int &a)
{
    return &a; 
}

int main()
{
   
    //函数指针(先指针,后函数)
    FUNC(pFunc);// int(*pFunc)(int, int) = NULL;
    pFunc = func;
    printf("%d\n",pFunc(1,2));

    F_FUNC p = NULL;
    p = func;
    printf("%d\n",p(3,5));


    //************华丽分界线**************

    //指针函数(先函数,后指针)(返回值是指针)
    int value = 5;
    FF pp = NULL;
    pp = ffunc;
    printf("%p\n",pp(value));

    return 0;
}
[user:函数指针和指针函数]

 

 

 

 

 

 

[user:函数指针和指针函数] g++ main.cpp
[user:函数指针和指针函数] ./a.out
3
8
0xbfcb0ba0
[user:函数指针和指针函数] g++ main.cpp
[user:函数指针和指针函数] ./a.out
3
8
0xbff259e0
[user:函数指针和指针函数] ls
a.out*  main.cpp

原创粉丝点击