Interview Question
Country: United States
Interview Type: Phone Interview
the above answer is wrong! I don't understand why someone vote it ,
what Anonymous described should be something like this :
{
void (*abc)(int, void (*def)());
}
but ...
Note void (*abc(...))(), what does this mean is abc return pointer to a function which take no args and return void, that is what abc is ,abc take a function pointer and return the same type of function pointer,
you can do this
{
void(*def)();
void (*abc(int, void(*def)()))();
def=(*abc)(0,def);
}
to simplify this ,we can use typedef
{
typedef void(*q)();
typedef q (*p)(int,q);
// then we can do something like below:
q b;
p a;
b=(*a)(0,b);
}
void (*def)() is a function pointer which points a function without argument and return value.
Abc(int, void (*def)()) is a function with two arguments first is int, second is a function pointer.
void (*abc(int, void (*def)()))() is a function pointer without return value and argument. and the pointer is returned from abc(int, void (*def)()).
this is a typical function pointer definition void(*fun)(), but for this void (*fun(...))()???
abc is a function pointer that takes no parameter and returning A FUNCTION POINTER, the returned function pointer is of the function type which returns void and takes an integer and another function pointer. This other function pointer points to a function that takes no parameters and returns void.
abc is pointer to function returning void, which takes 2 arguments: int and def, where def is a pointer to a function returning void and taking no arguments.
- Anonymous June 06, 2012