Declare a pointer to a function which takes array of pointer to a function as an argument and return the pointer to a function.....
how to declare this function....
Printable View
Declare a pointer to a function which takes array of pointer to a function as an argument and return the pointer to a function.....
how to declare this function....
You really ought to do your own homework...
QuantumPete
use typedefQuote:
how to declare this function
and use the new type as you needCode:typedef int (* fpointer)(int,char*);
Code:
fpointer func(fpointer f[], size_t arr_size);
Thanks vart.. I am not able to understand can you explain me in detail vart....
I have used this example in the past for such posts. So this help you as well in explaining an example of using a function pointer and how to declare it, outside of main.
http://www.cplusplus.com/doc/tutorial/pointers.html
Note:Code:
int addition (int a, int b) {
return (a+b); }
int subtraction (int a, int b) {
return (a-b);}
int operation (int x, int y, int (*functocall)(int,int))
{
int g;
g = (*functocall)(x,y); //A pointer to a function type 4.12 and 1.34 of comp.lang.c FAQ.
return (g);
}
int main ()
{
int m,n;
int (*minus)(int,int) = subtraction;
m = operation (7, 5, addition);
n = operation (20, m, minus);
printf("%d\n", n);
return 0;
}
A function call actually requires a function pointer value before the
parentheses. In a typical "direct" function call, this pointer value
is obtained from the name of the function.
A function name (more generally, any expression of function type) is
implicitly converted to a pointer to the function in most contexts.
(The exceptions are when it's the operand of a sizeof operator, which
is illegal rather than yielding a pointer size, and when it's the
operand of a unary "&", which yields the address of the function.)
could be justCode:g = (*functocall)(x,y);
Code:g = functocall(x,y);