gpt4 book ai didi

c - 在 C 中使用函数作为参数

转载 作者:行者123 更新时间:2023-12-02 10:27:18 26 4
gpt4 key购买 nike

我正在尝试使用一个函数作为另一个函数的参数。我想根据我传递的函数获得不同的计算。我尝试通过编写以下程序来实现此目的:
http://pastebin.com/CJfFarVa
代码:

问题是我一遍又一遍地收到此错误:

trapeze.c:14:8: error: conflicting types for ‘exp2’
double exp2(int number);

trapeze.c: In function ‘main’:
trapeze.c:28:35: error: expected expression before ‘int’
exp_2 = trapeze(0, 1, n, exp2(int x));
^
trapeze.c:29:35: error: expected expression before ‘int’
exp_1 = trapeze(0, 1, n, exp1(int x));
^
trapeze.c: At top level:
trapeze.c:58:8: error: conflicting types for ‘exp2’
double exp2(int number)

注意:我不想使用函数指针。
抱歉,如果这是一个简单的问题。

最佳答案

更改对trapeze的调用:

exp_2 = trapeze(0, 1, n, exp2);
exp_1 = trapeze(0, 1, n, exp1);

关于c - 在 C 中使用函数作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22187054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com