如何使用函数指针数组?

编程入门 行业动态 更新时间:2024-10-26 22:25:45
本文介绍了如何使用函数指针数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我应该如何使用函数指针数组用C?

How should I use array of function pointers in C?

我该如何初始化呢?

推荐答案

您有一个很好的例子的在这里(函数指针数组),与语法的详细。

You have a good example here (Array of Function pointers), with the syntax detailed.

int sum(int a, int b); int subtract(int a, int b); int mul(int a, int b); int div(int a, int b); int (*p[4]) (int x, int y); int main(void) { int result; int i, j, op; p[0] = sum; /* address of sum() */ p[1] = subtract; /* address of subtract() */ p[2] = mul; /* address of mul() */ p[3] = div; /* address of div() */ [...]

要调用这些函数指针之一:

To call one of those function pointers:

result = (*p[op]) (i, j); // op being the index of one of the four functions

更多推荐

如何使用函数指针数组?

本文发布于:2023-07-29 08:38:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239143.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   指针   如何使用   函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!