i need for one of my projects
to pass a function into a function
example :
double differencial( double x , double dx , ??? func )
{
return ( func( x + dx ) - func( x ) ) / dx ;
}
what do i do whit ??? ?
and in my fuction ?
The way to declare variables which are pointers to functions is a little weird in C. Here is an example:
1 2 3
double div3( int a ) { return a / 3.0; }
double (*func)( int ) = div3;
func is the name of the variable. It's type is double (*)( int ), or, in other words,
a pointer to a function which returns a double and takes an int as parameter.
You can now call the function this way:
double answer = (*func)( 10 );
And this will call div3() with 10 as parameter and store the result in answer.