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. TCP十一种状态

    2.全部11种状态 2.1.客户端独有的:(1)SYN_SENT (2)FIN_WAIT1 (3)FIN_WAIT2 (4)CLOSING (5)TIME_WAIT . 2.2.服务器独有的:(1)L ...

  2. OC中加载html5调用html方法和修改HTML5内容

    1.利用webView控件加载本地html5或者网络上html5 2.设置控制器为webView的代理,遵守协议 3.实现代理方法webViewDidFinishLoad: 4.在代理方法中进行操作H ...

  3. L2-005. 集合相似度

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAzwAAAIRCAIAAAAA0S/lAAAgAElEQVR4nO3dzass133v//xPNTszDU

  4. PS切图(一)

    Photoshop界面设置 新建文件Ctrl+N,其中[预设]-[web],[宽度]-[1920],高度不定.[背景内容]-[透明],也可存储为预设. 移动设置(V) 建议不勾选[自动选择],选择[图 ...

  5. 代码管理工具 --- git的学习笔记二《git的工作原理》

    通过几个问题来学习代码管理工具之git 一.git是什么?为什么要用它?使用它的好处?它与svn的区别,在Mac上,比较好用的git图形界面客户端有 git 是分布式的代码管理工具,使用它是因为,它便 ...

  6. BZOJ 1927: [Sdoi2010]星际竞速

    1927: [Sdoi2010]星际竞速 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 2051  Solved: 1263[Submit][Stat ...

  7. MVC+EF6+Oracle,提示ORA-01918: user '***' does not exist

    1.在上下文里重载OnModelCreating:        //没用到这个方法         protected override void OnModelCreating(DbModelBu ...

  8. Coursera上一个不错的Java课

    地址:https://www.coursera.org/learn/java-chengxu-sheji/home/welcome 复习天昏地暗,看点视频调剂一下.发现这个讲的还是很不错的.北大毕竟比 ...

  9. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  10. [LeetCode] Find Leaves of Binary Tree 找二叉树的叶节点

    Given a binary tree, find all leaves and then remove those leaves. Then repeat the previous steps un ...