多种类型的指针

函数指针:

多种类型的指针总结:

 

比如用函数指针变量做参数,求最大值,最小值,和两数之和

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    int a, b, max(int , int), min(int , int), add(int , int );
    void process(int, int, int (*fun)(int , int));
    scanf("%d%d", &a, &b);
    process(a, b, max);
    process(a, b, min);
    process(a, b, add);
    return 0;
}
void process(int x, int y, int (*fun)(int , int))
{
    int result;
    result = (*fun)(x, y);
    printf("%d\n", result);
}
int max(int x, int y)
{
    return x > y ? x : y;
}
int min(int x, int y)
{
    return x > y ? y : x;
}
int add(int x, int y)
{
    return x+y;
}

 

posted on 2015-10-05 17:30  张明明_1  阅读(243)  评论(0编辑  收藏  举报

导航