An simple example:

#include<stdio.h>

int plus(int a,int b)
{
return a+b;
} int main()
{
int (*func)(int,int);
func=&plus; //point to the function ''plus(int,int)''
printf("the result is %d\n",(*func)(,));
return ;
}

Another example:

#include <stdio.h>
#define MAX_COLORS 256 typedef struct {
char* name;
int red;
int green;
int blue;
} Color; Color Colors[MAX_COLORS]; void eachColor (void (*fp)(Color *c)) {
int i;
for (i=; i<MAX_COLORS; i++)
(*fp)(&Colors[i]);
} void printColor(Color* c) {
if (c->name)
printf("%s = %i,%i,%i\n", c->name, c->red, c->green, c->blue);
} int main() {
Colors[].name="red";
Colors[].red=;
Colors[].name="blue";
Colors[].blue=;
Colors[].name="black"; eachColor(printColor);
}

For more,go to How do function pointers in C work?-Stackoverflow

tips~function pointer的更多相关文章

  1. C 函数与指针(function & pointer)

    C 函数与指针(function & pointer) /* * function.c * 函数在C中的使用 * */ #include <stdio.h> int noswap( ...

  2. 类非静态成员的函数指针 的使用 Function pointer of a non-static member function of a class

    you can get the pointer of the method, but it has to be called with an object typedef void (T::*Meth ...

  3. Function Pointer in Delpni

    program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TVoice = function(): Stri ...

  4. 指向函数的指针 ------ 函数指针(function pointer)

    函数指针: 指向函数的指针, 首先是一个指针, 这个指针指向一个函数. 函数具有可赋值给指针的物理内存地址,一个函数的函数名就是一个指针,它指向函数的代码.一个函数的地址是该函数的进入点,也是调用函数 ...

  5. 44(function pointer 2)

    #include<iostream> using namespace std; class A { public: int x; int sayhello() { cout<< ...

  6. 43(function pointer 1)

    #include<iostream> using namespace std; typedef int A; typedef void (*PF)(); typedef int (*P_A ...

  7. C++ function pointer and type cast

    http://www.cprogramming.com/tutorial/function-pointers.html http://www.cplusplus.com/doc/tutorial/ty ...

  8. 指针函数(Pointer Function)和函数指针(Pointer to Function或Function Pointer)

    一.指针函数 1.解释:指针函数很好理解:简单来说,就是一个返回指针的函数,本质是一个函数.如: int fun(int x,int y);    //这是一个普通函数的声明,返回值是一个int类型, ...

  9. jquery提示信息 tips

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

随机推荐

  1. win10用户文件夹重命名,启用administrator账户,删除文件夹时提示找不到该项目

    这一切都源自楼主洁癖一般的强迫症. 楼主在重置win10后的安装过程中用microsoft账户登录的电脑,发现用户文件夹名称怪怪的,于是想重命名一下.楼主发现重命名用户文件夹并不能简单地用F2搞定,于 ...

  2. Collections.shuffle

    1.Collections.shuffler 最近有个需求是生成十万级至百万级的所有随机数,最简单的思路是一个个生成,生成新的时候排重,但是这样时间复杂度是o(n^2),网上看了几个博客的解决方法都不 ...

  3. 使用NuGet发布自己的类库包(Library Package)

    STEP 1:注册并获取API Key 首先,你需要到NuGet上注册一个新的账号,然后在My Account页面,获取一个API Key,这个过程很简单,我就不作说明了. STEP 2:下载NuGe ...

  4. [LeetCode] Find K Pairs with Smallest Sums 找和最小的K对数字

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  5. 做中学(Learning by Doing)之背单词-扇贝网推荐

    做中学(Learning by Doing)之背单词-扇贝网推荐 看完杨贵福老师(博客,知乎专栏,豆瓣)的「继续背单词,8个月过去了」,我就有写这篇文章的冲动了,杨老师说: 有时候我会感觉非常后悔,如 ...

  6. Android实现类似换QQ头像功能(图片裁剪)

    现在几乎所有的App都有用户登录模块,需要设置用户头像,而关于用户头像部分无疑也是比较头疼的,目前大部分应用的头像部分会有两种方式:一种是利用系统的裁剪功能去获取用户头像,一种就是获取到图片或者照片的 ...

  7. TypeScript 2.0候选版(RC)已出,哪些新特性值得我们关注?

    注:本文提及到的代码示例下载地址 - Runnable sample to introduce Typescript 2.0 RC new features 作为一个Javascript的超集, Ty ...

  8. ACM模板(持续补完)

    1.KMP #include<cstring> #include<algorithm> #include<cstdio> using namespace std; ...

  9. JavaScript中实现extend()方法

    var male = { sex: "male" }; var xiaoming = { name: "xiaoming", school: "xin ...

  10. U8采购订单联查采购入库单

    1.表头rdrecord01,字段ipurorderid(采购订单ID), cOrderCode(采购订单号)要与采购订单表头主键和单号对应 表体rdrecords01,字段cPOID(采购订单号), ...