tips~function pointer
An simple example:
#include<stdio.h> int plus(int a,int b)
{
return a+b;
} int main()
{
int (*func)(int,int);
func=+ //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的更多相关文章
- C 函数与指针(function & pointer)
C 函数与指针(function & pointer) /* * function.c * 函数在C中的使用 * */ #include <stdio.h> int noswap( ...
- 类非静态成员的函数指针 的使用 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 ...
- Function Pointer in Delpni
program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TVoice = function(): Stri ...
- 指向函数的指针 ------ 函数指针(function pointer)
函数指针: 指向函数的指针, 首先是一个指针, 这个指针指向一个函数. 函数具有可赋值给指针的物理内存地址,一个函数的函数名就是一个指针,它指向函数的代码.一个函数的地址是该函数的进入点,也是调用函数 ...
- 44(function pointer 2)
#include<iostream> using namespace std; class A { public: int x; int sayhello() { cout<< ...
- 43(function pointer 1)
#include<iostream> using namespace std; typedef int A; typedef void (*PF)(); typedef int (*P_A ...
- C++ function pointer and type cast
http://www.cprogramming.com/tutorial/function-pointers.html http://www.cplusplus.com/doc/tutorial/ty ...
- 指针函数(Pointer Function)和函数指针(Pointer to Function或Function Pointer)
一.指针函数 1.解释:指针函数很好理解:简单来说,就是一个返回指针的函数,本质是一个函数.如: int fun(int x,int y); //这是一个普通函数的声明,返回值是一个int类型, ...
- jquery提示信息 tips
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
随机推荐
- ajax 允许跨域html头设置
"Access-Control-Allow-Origin"= "*" "Access-Control-Allow-Headers"= &qu ...
- 【FLUENT案例】02:DPM模型
1 引子1.1 案例描述1.2 学习目标1.3 模拟内容2 启动FLUENT并导入网格3 材料设置4 Cell Zones Conditions5 Calculate6 定义Injecions7 定义 ...
- django 一些相关问题
这两天在处理django项目时碰到一些问题 1.ur路径设置要忽略大小写,查找了很多资料,都没有发现相关的介绍,最后在谷歌上找到一个解决方案,https://groups.google.com/for ...
- 最短路径算法-Dijkstra
Dijkstra是解决单源最短路径的一般方法,属于一种贪婪算法. 所谓单源最短路径是指在一个赋权有向图中,从某一点出发,到另一点的最短路径. 以python代码为例,实现Dijkstra算法 1.数据 ...
- [AR]ImageTarget(图像识别)
ImageTarget 前言 ImageTarget 顾名思义,就是图像识别,本文记录下作者最近学习vuforia中的imageTarget笔记与心得. vuforia guide:https://l ...
- 升级xcode8之后出现报错提示,提示swift版本问题
最近Xcode升级了,出现了各种蛋疼的错误提示,今天遇到个导入框架出现了提示Swift版本的问题,具体如下: "Use Legacy Swift Language Version" ...
- 利用线上数据验证系统 Gor
Web 应用性能和压力测试工具 Gor - 运维生存时间 http://hao.jobbole.com/gorhttp/ 要使用线上引流到测试环境的作用,需要做到以下几点: 1.新搭建一套测试环境,连 ...
- MikroTik RB750r2 操作记录
1. 客户端的下载 http://www.mikrotik.com/download 下载 winbox 2. Reset重置密码的正确姿势 http://wiki.mikrotik.com/ind ...
- Android开发之带你轻松集成友盟统计
友盟统计是什么呢?为什么要集成他呢? 当我们需要获取自己写的软件的装机量和用户使用信息时,这时我们可以集成友盟统计. 首先到友盟统计中注册账号什么的就不废话了,直接看创建项目: 在个人中心中的管理里面 ...
- openssl+前端jsrsa签名+后端nodejs验签
内容如标题所示,总体分为三个部分: 一.win10下安装openssl,然后通过openssl工具生成RSA的公钥和私钥 (1)win10下安装openssl需要的工具有:VS2013,Perl,na ...