The program will look like
#include<stdio.h>
int sum( int, int );
void print( int ( * )( int, int ), int, int );
// or more simpler
void print( int ( int, int ), int, int );
int main()
{
int a = 2;
int b = 5;
print( sum, a, b);
}
void print( int ( *p )( int,int ), int a, int b )
{
printf( "%d", p( a, b ) ); //a and b are not defined as per compiler
}
int sum( int a, int b )
{
return a + b;
}
Take into account that these declarations are equivalent and declare the same function
void print( int ( * )( int, int ), int, int );
// or more simpler
void print( int ( int, int ), int, int );
As for your original code then function print only has one parameter: a function pointer. So you may pass to function print only one argument: some function. You could define function print the following way
void print( int ( *p )( int,int ) )
{
int a = 2, b = 5;
printf( "%d", p( a, b ) ); //a and b are not defined as per compiler
}
Or you can define function print with three parameters that the user of the function could himself specify arguments to the called function within the body of print.
void print( int ( *p )( int,int ), int a, int b )
{
printf( "%d", p( a, b ) ); //a and b are not defined as per compiler
}