wanderer wanderer - 1 year ago 90
C Question

Function pointer for inverse of exp function in c

I am trying to define a function pointer which calculates e^-x.
Something similar to C# equivalent:

Func<double, double> f = x => Math.Exp(-x);

I tried in vain by doing something like:

double(*negativeExp(double x))(double) {
double eValue = exp(1);
return pow(eValue, -x);

Any ideas.

Answer Source

The code for the function would be:

double f(double x)
    return exp(-x);

Then you can make a pointer to that function. Sample use:

int main(void)
    double (*p)(double) = &f;

    printf("f(1) == %f", p(1));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download