To declare a function that returns a pointer to a function, first write the declaration of the return type of the function. For example, the type of a function that takes two int and returns int :
int function(int, int)
Now make it a function pointer by inserting * . Since priority interferes (function parameters in brackets will be more closely tied to the identifier than * ), we must also insert parentheses:
int (*function)(int, int)
Finally, replace the identifier with the declarator of the factory function. (To this end, the declarator is a function identifier and a list of parameters.) In this case, we replace function with factory(int) . This gives:
int (*factory(int))(int, int)
Declares a factory(int) function that returns what matches the place where xxx is in int (*xxx)(int, int) . What fits in this place is a function pointer with two int and returns an int .
source share