C 中的函数参数 [英] Function Arguments in C

查看:29
本文介绍了C 中的函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 C 完全陌生.问题是:

I'm totally new to C. Here's the question:

编写函数

fzero(double f(double),double x1, double x2)

就像我们在课堂上所做的那样,并用它来找到

as we did in class and use it to find all the solutions of

sin( pi*x / (1+x^2) ) = 0.25.

现在,我不想让你解决这个问题.我错过了这个讲座,只想了解是什么意思

Now, I don't want you to solve the this. I'd missed this lecture and only want to understand what means

double f(double);

推荐答案

在那个上下文中,它意味着 f 是一个 函数指针 到一个函数double 参数,并返回一个 double.

In that context, it means that f is a function pointer to a function to that takes one double argument, and returns a double.

举个例子:

void foo(double f(double))
{
    double y = f(3.0);  // Call function through function pointer
    printf("Output = %f\n", y);   // Prints "Output = 9.0000"
}

double square(double x)
{
    return x*x;
}

int main(void)
{
    foo(&square);  // Pass the address of square()
}

注意函数指针有两种语法:

Note that there are two syntaxes for function pointers:

void foo(double f(double))
void foo(double (*f)(double))

这些是等价的.

这篇关于C 中的函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆