在C函数参数 [英] Function Arguments in C

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

问题描述

我完全陌生C.这里的问题:


  

编写函数

  fzero(双F(双),双X1,X2双)


  
  

因为我们没有在课堂上,并用它来找到所有的解决方案

 罪(PI * X /(1 + X ^ 2))= 0.25。


现在,我不希望你来解决这一点。我已经错过了这次演讲,只有想明白拿什么

 双F(双);


解决方案

在这种情况下,这意味着˚F函数指针以该功能需要一个双击参数,并返回一个双击

作为一个例子:

 无效美孚(双F(双))
{
    双Y = F(3.0); //通过函数指针调用函数
    的printf(输出=%F \\ N,Y); //输出输出= 9.0000
}双广场(双X)
{
    返回X * X;
}INT主要(无效)
{
    富(安培;广场); //把方形的地址()
}

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

 无效美孚(双F(双))
无效美孚(双(* F)(双))

这是等同的。

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

Write the function

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);

解决方案

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

As an example:

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))

These are equivalent.

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

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