结构体中函数指针的用法。
2012-05-13 14:29
288 查看
/* *结构体中函数指针的用法。 */ #include <stdio.h> struct DEMO1 { int (*func)(int, int); }; static int add(int a, int b) { return (a + b); } int main(void) { int (*p)(); struct DEMO1 test; test.func = add; // add 为函数名,和数组一样,代表函数的首地址,是个常量。把add的地址传给func. printf("the result is %d\n", (*test.func)(2, 3));//(*test.func)() = (test.func)() = add printf("the result is %d\n", test.func(5, 3)); }
相关文章推荐
- C语言结构体指针,函数指针的用法
- c语言结构体中保存函数指针的用法
- typedef 函数指针的用法
- [编程] C语言结构体指针作为函数参数
- typedef函数指针的用法
- 结构体中指向函数的指针
- C语言开发函数库时利用不透明指针对外隐藏结构体细节
- typedef函数指针的用法
- 【C 语言】结构体相关 的 函数 指针 数组
- [C++基础]typedef 函数指针的用法
- 结构体中的函数指针
- C 函数指针的用法
- 函数指针的用法
- typedef函数指针用法
- 成员函数指针的用法
- 结构体变量、结构指针变量、结构数组作为函数的参数应用实例分析 .
- 函数指针用法 以及typedef 优化函数指针
- c/c++ 函数指针的用法
- C语言结构体内嵌函数指针
- [C++] C++中const修饰指针,变量, 函数参数和函数返回值的用法总结